CXF 2.7.13
eclipse:3.5
Official website: http://cxf.apache.org/index.html
The first step is to create the service side
1, create Dynamic Web project, Guide CXF jar Package
2, create the interface and implementation class, the following figure
3, Helloworld.java Code
Package com.lu;
Import Javax.jws.WebMethod;
Import Javax.jws.WebParam;
Import Javax.jws.WebService;
@WebService Public
interface HelloWorld {
@WebMethod public
string SayHello (string name);
}
Helloworldimpl.java Code
Package Com.lu.impl;
Import Javax.jws.WebService;
Import Com.lu.HelloWorld;
@WebService (endpointinterface= "Com.lu.HelloWorld", Servicename= "Helloworldws") Public
class Helloworldimpl Implements HelloWorld {
@Override public
string SayHello (string name) {return
"Hello world,i am cxf!" +name;
}
public static void Main (String args[]) {
HelloWorld hw = new Helloworldimpl ();
String address = "Http://localhost/hello";
Javax.xml.ws.Endpoint.publish (address, HW);
System.out.println ("WebService run ...");
}
4, if successful, then enter the WSDL address in the browser, get the following interface
The second step is to create a client call
1, create Java project, named "Cxfclient"
2, configure Wsdl2java, if there is a problem, then add CXF package bin to the path path until the following interface appears
3, switch to cxfclient under the SRC path, execute command Wsdl2java http://localhost/hello?wsdl
4, after refreshing the SRC directory, get the following files
5, the new client Invoke class Cxfclient.java, the code is as follows:
Package com.lu;
Import Com.lu.impl.HelloWorldWS;
public class Cxfclient {public
static void Main (String args[]) {
Helloworldws hwws = new Helloworldws ();
HelloWorld HW = Hwws.gethelloworldimplport ();
System.out.println (Hw.sayhello ("from Apache"));
}
Console output "Hello world,i am cxf!from Apache"