Apache CXF is an open source framework that provides a reliable infrastructure for easy building and development of WEB services. It allows you to create high-performance and scalable services that you can deploy in Tomcat and Spring-based lightweight containers, and on more advanced servers, such as Jboss, IBM WebSphere, or BEA WebLogic.
Simply introduce the Getting Started tutorial and record it for yourself.
(1) Download CXF package, http://cxf.apache.org/download.html, I use 2.4.0 's bag here.
Import all jar packages in Lib, we recommend using library mode
(2) Write the WebService interface class, the interface implementation class is as follows
The interface needs to specify annotation
@WebServicepublic interface Ihello {public string Sayhi (string name); public string Printname (string name);}
Write the implementation class for the above interface, annotation specifies endpointinterface and servicename
@WebService (endpointinterface= "Com.xj.service.IHello", Servicename= "Hello1service") public class Helloimpl Implements ihello{@Overridepublic string Sayhi (string name) {System.out.println ("Hi," +name); return "Hi," +name;} @Overridepublic string Printname (string name) {System.out.println ("My name is," +name); return "My name is," +name;}}
(3) Write the service side and start
public class Runserver {public static void main (string[] args) {Ihello Hello = new Helloimpl (); Endpoint.publish ("Http://localhost/cxf/hello", hello); SYSTEM.OUT.PRINTLN ("Start server Side");}}
The same endpoint is used here to publish the service, and of course you can use Jaxwsserverfactorybean
Run the Main method, access http://localhost/cxf/hello?wsdl to see the WSDL file for the service
(4) Writing the client
public class Runclient {public static void main (string[] args) {Jaxwsproxyfactorybean proxy = new Jaxwsproxyfactorybean (); Proxy.setserviceclass (Ihello.class);p roxy.setaddress ("http://localhost/cxf/hello?wsdl"); Ihello hello = (Ihello) Proxy.create (); System.out.println (Hello.sayhi ("Xiejun")); System.out.println (Hello.printname ("Xiexie"));}}
Use Jaxwsproxyfactorybean to create the proxy, specify the service class, specify the WSDL address,
Call the Create method of the proxy class to access all methods
This article is from the "Bulajunjun" blog, make sure to keep this source http://5148737.blog.51cto.com/5138737/1606249
CXF Implementation WebService