Server: See my previous blog post (Java calls the WebService interface using Xfire)
Client: In the Bin folder of the JDK, there is a wsimport.exe, which generates the corresponding class file based on the WSDL file, and then uses these class files to invoke the WebService provider as if it were a local class. The tool can be used for non-Java servers, such as WebService written in C #, which generates a Java client implementation through Wsimport.
Use the following command at the command prompt: Wsimport-keep-p com.demo.client http://localhost:8080/Demo/services/MyService?wsdl
Command parameter Description:
-D: Generate Directory of class files for client execution classes
-S: Generate a directory of source files for the client execution class
-P: Define the package name of the generated class
For additional command parameters, please refer to: http://download-llnw.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html
After using the Wsimport command, we can get the following code file:
The current directory on the command line
|--com
|--demo
|--client
|--example.java
|--exampleresponse.java
|--myservice.java
|--myserviceporttype.java
|--objectfactory.java
|--package-info.java
You can copy the above files to your project and use them.
Test: Create a new project, and copy the Com.demo.client package to the project file, write the test file Test.java, the code is as follows:
Package Com.demo.wsimport;public class Test {/** * @param args*/public static void Main (string[] args) { TODO auto-generated Method Stub myservice Server = new MyService (); Myserviceporttype SPT = Server.getmyservicehttpport (); System.out.println (spt.example ("Hello")); }}
Build WebService client using command Wsimport