Project background
The task is to obtain their image data by invoking the WebService interface provided by other platform vendors to download the images and enter our platform. Had not contacted WebService before, so began this WebService rookie tour.
First, to Baidu check the simple set up a WebService server and the client's small demo, to understand its work flow
Service-Side Building
1. Create a new Java project with the following directory
2. Create a new class, annotated @webservice, the main content is as follows
PackageWebservice_serverdemo;ImportJavax.jws.WebMethod;ImportJavax.jws.WebService;Importjavax.xml.ws.Endpoint; @WebService Public classTest {/**for the client to invoke the method the method is non-static and will be published *@paramname incoming parameter *@returnString Returns the result **/ Publicstring GetValue (string name) {return"Welcome you!" "+name; } /*** method is added @webmentod (exclude=true), this method is not published;@paramname *@return */@WebMethod (Exclude=true) Publicstring Gethello (string name) {returnHello "+name; } /**static methods are not published *@paramname *@return */ Public Staticstring getString (string name) {returnGoodbye "+name; } //publish a WebService through endpoint (endpoint service) Public Static voidMain (string[] args) {/*parameters: 1, local Service address; 2, the provision of service classes; */Endpoint.publish ("Http://127.0.0.1:8080/Test",NewTest ()); System.out.println ("Successful release!"); //after the publication succeeds in the browser inputhttp://localhost: 8080/test?wsdl }}
3. Run the Main method, the console displays the publishing success
4. Browser input http://localhost:8080/Test?wsdl can see the generated WSDL file, the service end is built
Client Building
1. Create a new Java project
2. Click on the project Right >new>other>web service client> fill in the WSDL address such as (make sure the server does not close, the browser access address can see the XML) can also be filled out is a WSDL file path
After finish, you will find that the client's folder and Java class are generated under SRC, and the interface can be called at the client.
Call and try.
PackageWebservice_serverdemo;Importjava.rmi.RemoteException;ImportJava.util.Iterator;Importjavax.xml.rpc.ServiceException; Public classHello { Public Static voidMain (String []args)throwsremoteexception, serviceexception{testservicelocator test=NewTestservicelocator (); Test Ports=Test.gettestport (); System.out.println (Ports.getvalue (Cortana)); }}
Console output, you can see that there is a warning because of the lack of Mail.jar and Activation.jar, you can download it yourself without adding or having a particularly big impact
Return to Project
As you can see from the small demo above, Eclipse can be called automatically based on the WSDL generated by the client, which is very simple. But, through the platform vendor feedback WSDL file found that because their system is very old, the generated WSDL can not be used in this way to generate the client, then replaced a method, using axis1.4 to generate the client
1. Download the Axis-bin-1_4.zip jar package, unzip
2. Enter the Lib directory to open cmd run
D:\soft\axis-1_4\lib>java-djava.ext.dirs=d:\soft\axis-1_4\lib Org.apache.axis.wsdl.wsdl2java-o D:\zhuhai-p Com.ws D:\soft\axis-1_4\RequestService.wsdl
Java-djava.ext.dirs=${lib Directory} org.apache.axis.wsdl.wsdl2java-o${code output path}-p${package name} ${wsdl path (can be an absolute path or URL)}
Will report a warning, no relationship, mentioned above
-Unable to find required classes (Javax.activation.DataHandler and Javax.mail.internet.MimeMultipart). Attachment support is disabled.
3. Go to ${code output path} to find the generated client
WebService rookie Discovery Tour