1. Pom.xml joins CXF's dependency
<!--Https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-frontend-jaxws--
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.7.18</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.7.18</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.1.12</version>
</dependency>
2. Code
2.1 Basic Parameter type invocation
jaxwsdynamicclientfactory DCF = Jaxwsdynamicclientfactory.newinstance ();
Client client = dcf.createclient ("xxx.wsdl");
/*echo: Method Name
*test Echo: Parameters
*/
object[] res = Client.invoke ("echo", "Test echo");
SYSTEM.OUT.PRINTLN ("Echo response:" + res[0]);
2.2 Object Invocation
jaxwsdynamicclientfactory DCF = Jaxwsdynamicclientfactory.newinstance ();
Client client = dcf.createclient ("xxx.wsdl");
Object person = Thread.CurrentThread (). Getcontextclassloader (). LoadClass ("Com.acme.Person"). newinstance ();
Method m = Person.getclass (). GetMethod ("SetName", String.class);
M.invoke (Person, "Joe Schmoe");
Method m1 = Person.getclass (). GetMethod ("Setcustomerid", String.class);
Method m2 = Person.getclass (). GetMethod ("Setitemid", String.class);
Method m3 = Person.getclass (). GetMethod ("Setqty", Integer.class);
Method M4 = Person.getclass (). GetMethod ("Setprice", Double.class);
M1.invoke (person, "C001");
M2.invoke (person, "I001");
M3.invoke (person, 100);
M4.invoke (person, 200.00);
Client.invoke ("Addperson", person);
3. How to generate a xxx.wsdl file
such as: Http://www.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx?WSDL
Browser Open the above address, ctrl+s directly save, the default is an XML file, can be changed to WSDL, also do not change, the code directly with the XML
When Java calls. NET's Web service service, it generates an exception that requires a WSDL file to be modified, directly commenting out <s:element ref= "S:schema"/>
4. Wsdl2java tool generates Java client calling code
4.1 Downloads for Apache CXF (http://cxf.apache.org/download.html)
4.2 Download and use the CD directly to the CXF Bin directory, the purpose is to see the bean inside the method name and properties
C:\java\apache-cxf-3.1.14\bin>wsdl2java-p client-d C:\java C:\java\***.xml
A more direct description of the website (http://cxf.apache.org/docs/dynamic-clients.html)
Spring Boot integrated Apache CXF calls. NET Service-side WebService