I. Environmental preparedness
1, JDK Environment
2, download APACHE-CXF release package, currently the latest version of 3.1.7, unpack the release package, set the Cxf_home, and add%cxf_home%/bin to the PATH environment variable.
3, cmd command line input wsdl2java-help, there are normal prompts to indicate that the environment has been properly configured.
Second, the use of orders
This command is mainly generated WebService client code, the server can be self-developed services, can also be a docking service interface, the simplest commands are as follows:
Wsdl2java Wsdlurl
Where Wsdlurl is the access address that is published for the service, the unnamed parameter generates the client-side code, where the most used is the-encoding parameter, which is the encoding format for the specified Java code, for example:
Wsdl2java-encoding Wsdlurl
Other detailed parameters and instructions can be obtained with wsdl2java-help or wsdl2java-h, according to the actual requirements of the corresponding parameters can be set.
Third, simple case
Common interface: IP address source Search WEB Service
1. Generate client code
WSDL Address:
http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl
Using the Wsdl2java tool to generate direct client code in Eclipse's engineering, the Eclipse Project address is: E:\workspace\webservice, as follows:
Wsdl2java-encoding Utf-8-D e:/workspace/webservice/src http://www.webxml.com.cn/WebServices/ ipaddresssearchwebservice.asmx?wsdl
1 1
-encoding indicates that the generated Java file encoding format is utf8,-d to indicate that the code generation path is E:/WORKSPACE/WEBSERVICE/SRC.
Execution completed without any errors, indicating successful execution
You can see that the corresponding code has been generated below eclipse:
2. Client Code Invocation Service
Write a small demo, invoke the published IP query service
package Com.hy.ipservice;
Import Java.util.Iterator;
Import java.util.List;
Import cn.com.webxml.ArrayOfString;
Import Cn.com.webxml.IpAddressSearchWebService;
Import Cn.com.webxml.IpAddressSearchWebServiceSoap; public class Ipservicedemo {public static void main (string[] args) {Ipaddresssearchwebservice Service2 = NE
W Ipaddresssearchwebservice ();
Ipaddresssearchwebservicesoap Servicesoap = Service2.getipaddresssearchwebservicesoap ();
Arrayofstring Citybyip = Servicesoap.getcountrycitybyip ("58.60.251.125");
list<string> ips = citybyip.getstring (); for (iterator<string> ite = Ips.iterator (); Ite.hasnext ();)
{String ip = (string) ite.next ();
SYSTEM.OUT.PRINTLN (IP); }
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 1 2 3 4-5--6 7---8 9--10 11 12 13 14 15 16-17 18 19 20
The results obtained are:
Info: Creating Service {Http://webxml.com.cn/}ipaddresssearchwebservice from wsdl:http://www.webxml.com.cn/ webservices/ipaddresssearchwebservice.asmx?wsdl
58.60.251.125
Guangdong Province Shenzhen Telecom