Usage Environment: MyEclipse9.0
This tutorial uses the MyEclipse built-in plug-in to generate Java code, which is said to be a xfire plug-in, anyway, it is very simple to generate and invoke client code.
1. Right-click on the project and select New->other->web service->web Service client->next to see the following interface:
Here you can select the WSDL file, or write the URL address of the WSDL, it is recommended to write the URL, so that the call does not need to modify the generated code. Then use the default settings all the way next, last finish.
2. Calling the procedure
After generating the code, you will find that SRC has more than one package, and the name of the package is related to the namespace of the Web service.
We can look at the Java file named after the name PortType in WSDL, this is Service1soap.java, which is an interface that contains all the methods in the Web service.
Let's start with the call procedure, take the Add method above as an example, start with a new Service1 object, then create a Service1Soap object from the service object, and finally call the desired method, with the following code:
[Java]View PlainCopy print?
- Service1 service = new Service1 ();
- Service1Soap soap = Service.getservice1soap ();
- System.out.println (Soap.add (3, 4));
PS: Using this plugin can also check the correctness of the WSDL, you can open a WSDL file by using MyEclipse, if the file does not conform to the WSDL specification, the left side will appear warning. In addition, during the creation of the Web service client, the plug-in also validate the WSDL file, and if there is an error, no code is generated. Note: The plug-in error will have the wrong code, this is the WSDL rule, you can view the error code on http://ws-i.org/profiles/basicprofile-2.0-2010-11-09.html.
Using the MyEclipse plugin to generate Java client code for WSDL