Spring Boot integrated Apache CXF calls. NET Service-side WebService

Source: Internet
Author: User
Tags wsdl

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.