First, CXF generate WebService Client
1. Interface Path HTTP://LOCALHOST:8080/CXFSERVER/WEBSERVICE/USERWS?WSDL
2. Enter the package where you need to place the WebService client code, enter the system path where the package resides, and go to cmd
3. Execute command wsimport-keep http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl or wsdl2java-client http:// ws.webxml.com.cn/webservices/weatherws.asmx?wsdl
3.1, if the error message is as follows: the same name "XXX" class/interface has been used.
Wsdl2java-client http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl
Switch
Wsdl2java-client -autonameresolution http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl
4, Spring Integration CXF
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:jaxws= "Http://cxf.apache.org/jaxws"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.0.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context /spring-context-3.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd "> <jaxws:clientID= "Userclient"ServiceClass= "Com.java.webservice.service.impl.ITianQi"<!--generated interfaces-->address= "Http://ws.webxml.com.cn/WebServices/WeatherWS.asmx" ></jaxws:client></Beans>
Second, HttpClient call WebService
Public StaticString GetXML () {StringBuffer sb=NewStringBuffer (); Sb.append ("<?xml version= ' 1.0 ' encoding= ' utf-8 '?>" + "<soap:envelope xmlns:xsi= ' Http://www.w3.org/2001/XMLSchema -instance ' xmlns:xsd= ' http://www.w3.org/2001/XMLSchema ' xmlns:soap= ' http://schemas.xmlsoap.org/soap/envelope/' > "+" <soap:Body> "+" <getmobilecodeinfo xmlns= ' http://WebXml.com.cn/' > "+" <mobil Ecode>string</mobilecode> "+" <userID>string</userID> "+" </getMobileCodeInfo> "+" </soap:Body> "+" </soap:Envelope> "); returnsb.tostring ();}
Static intSockettimeout = 30000;//request time-out periodStatic intConnectTimeout = 30000;//transmission Time-out period Public Staticstring DoPost () {string PostURL= "Http://ws.webxml.com.cn/WebServices/WeatherWS.asmx"; String SOAPAction= ""; String Soapxml=GetXML (); String Retstr= ""; //Create HttpclientbuilderHttpclientbuilder Httpclientbuilder =httpclientbuilder.create (); //HttpClientCloseablehttpclient closeablehttpclient =Httpclientbuilder.build (); HttpPost HttpPost=NewHttpPost (PostURL); //set the request and transmit timeout timesRequestconfig Requestconfig =Requestconfig.custom (). SetSocketTimeout (Sockettimeout). Setconnecttimeout (ConnectTimeout). build (); Httppost.setconfig (Requestconfig); Try{Httppost.setheader ("Content-type", "Application/soap+xml;charset=utf-8"); Httppost.setheader ("SOAPAction", SOAPAction); Stringentity Data=NewStringentity (Soapxml, Charset.forname ("UTF-8")); Httppost.setentity (data); Closeablehttpresponse Response=Closeablehttpclient.execute (HttpPost); Httpentity httpentity=response.getentity (); if(Httpentity! =NULL) { //Print Response ContentRetstr = entityutils.tostring (httpentity, "UTF-8"); } //Freeing ResourcesCloseablehttpclient.close (); } Catch(Exception e) {}returnretstr;}
CXF Generating WebService Client