CXF Implementation WebService

Source: Internet
Author: User

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

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.