WebService Summary

I haven’t written for three years. . . So fast. . After work, I picked it up again. Although I have not done ACM for a long time, it is always a pleasure to share knowledge with everyone.

Let’s talk about the WebService commonly used in projects. WebService technology is a cross-platform, very low-coupling application. Actual scenario:

1. Provide the WSDL address of the WebService and require us to call the methods in it to complete some business logic. At this time, we call the service on the client side, and others provide the service on the server side.

Suppose there is such a WSDL address, 10.112.11.145:9902/App/MyImplService?WSDL; defines a method void add(int x,int y);

< br>

We enter this WSDL address in the browser address (provided it is valid), and we can see some XML, usually SOAP messages.

When developing,

The first step: Open the DOS window of CMD and enter the bin of your jdk installation directory. For example, mine is D:/jdk1.6.0_26/ bin, use the wsimport.exe tool provided by jdk to generate the java code we need locally.

The command is as follows:

wsimport -s D;\Test\src http://10.112.11.145:9902/App/MyImplService?WSDL,

Just You can get our java code in the specified Src directory.

Step 2:

Import the Java file obtained above directly into our project Just like using an existing Java file, it can be used directly, and the calling process is also very simple.

MyImplService service = new MyImplService();MyImpl serviceImpl = service.getMyImplPort() ;serviceImpl.add(xx,xx);

This completes the call of the entire process.

2. Service provider. As the provider of WebService, we develop the interface, and others call our service, just like our operation in 1.

I believe that many people have done this. It is very simple.

The first step: define the interface according to your specific business logic.

package com.sgx.webservice;import javax.jws.WebService;@WebServicepublic interface Hello {void sayHello();}< /pre> 

第二步:完成实现类

package com.sgx.webservice;import javax.jws.WebService;@WebServicepublic class HelloImpl implements Hello{ @Override public void sayHello() {System.out.println("Hello,World! "); }}

Step 3: Publish WebService,

1. If it is a local project, just use Endpoint.publish(yourwsdl) in java .

2. If you want to use other environments (test, production ==) at this time, we only need to define our WebService interface, WebMethod and so on.

If it is a WebLogic server, you don’t need to write a Listener, you only need to define the interface and implementation class, so that when the application starts, it will automatically detect the WebService service and publish it,

We can enter the address in the browser to verify it.

If it is a Tomcat server, a Listner should also be implemented to publish the service. Only in this way can the service be published. (Please verify by yourself under Tomcat.)

Then others can call our published service.

Leave a Comment

Your email address will not be published.