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