Java calls CXF WebService interface in two ways

Source: Internet
Author: User

Access to XML via HTTP://LOCALHOST:7002/CARD/SERVICES/HELLOWORLD?WSDL is as follows, indicating that the interface is written to the right.

2. Static Calls

Create a WebService Client Agent factory
Jaxwsproxyfactorybean factory = new Jaxwsproxyfactorybean ();
Determine whether to throw an exception
Factory.getoutinterceptors (). Add (New Loggingininterceptor ());
Registering the WebService interface
Factory.setserviceclass (Deductionservice.class);
Configuring WebService Addresses
Factory.setaddress ("http://localhost:7002/card/services/HelloWorld?wsdl");
Get Interface Object
Cxfservice service = (cxfservice) factory.create ();
Calling interface methods
String result = Service.sayhello ("aaaaaaaaaa");
SYSTEM.OUT.PRINTLN ("Call Result:" + result);
To close an interface connection
System.exit (0);

3. Dynamic invocation:

jaxwsdynamicclientfactory DCF = Jaxwsdynamicclientfactory.newinstance ();
Org.apache.cxf.endpoint.Client Client = DCF
. CreateClient ("http://localhost:7002/card/services/HelloWorld?wsdl");
URL is the WSDL address that calls WebService
QName name = new QName ("http://dao.xcf.digitalchina.com/", "SayHello");
Namespace is a namespace, MethodName is the method name
String xmlstr = "AAAAAAAA";
Paramvalue is a parameter value
Object[] objects;
try {
objects = Client.invoke (name, XMLSTR);
System.out.println (Objects[0].tostring ());
} catch (Exception e) {
E.printstacktrace ();
}

The difference: A static call needs to rely on the service class, because the client calls the CXF WebService interface to provide service on the server side, it is inconvenient, if there is no difference in the same project.

Dynamic calls do not depend on the service class at all, and the server side can be easily called as long as the interface name and path are provided.

Java calls CXF WebService interface in two ways

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.