Using CXF and spring to develop Web Service under MyEclipse

Source: Internet
Author: User
Tags wsdl

"Learning notes for the Web Service Li Gang Video"

One. Using CXF to develop Web servive server-side (new Java project name Ws_server)//Each Web service component requires 2 parts, interfaces, and implementation classes.

  1. Develop aWEB Service Business Interface, the interface to be decorated with @webservice, the new com.hnu.cxf.ws under the SRC package, under the package to create a new business interface called HelloWorld, HelloWorld code as follows:
    1  Package com.hnu.cxf.ws; 2 3 Import Javax.jws.WebService; 4 5 @WebService// 6public interface provided by Javax.jws.WebService   HelloWorld {7    string Sayhi (string name); 8 }

  2. Develop a Web service business interface implementation class, which is also decorated with @webservice, but to specify two properties Endpointinterface and ServiceName, Create a new Com.hnu.cxf.ws.impl package under SRC, create a new implementation class for the HelloWorld business interface, and the Helloworldws.java code is as follows:
    1  PackageCom.hnu.cxf.ws.impl;2 3 Importjava.util.Date;4 5 ImportJavax.jws.WebService;6 7 ImportCom.hnu.cxf.ws.HelloWorld;8 9 //The value of Endpointinterface is the name of the interface to be implemented, and the name of the ServiceName property can be specified arbitrarilyTen@WebService (endpointinterface= "Com.hnu.cxf.ws.HelloWorld", servicename= "Helloworldws") One  Public classHelloworldwsImplementsHelloWorld { A  - @Override -      Publicstring Sayhi (string name) { the         //TODO auto-generated Method Stub -          -         returnName+ ", Hello! Time is now" +NewDate (); -     } +}

  3. Import the relevant jar package for CXF and publish the service. You can also import all the jar packages in the cxf Lib directory, cxf the jar package contains the jetty Web server, and then create a new Chen package, write a main program Servermain.java, the code is as follows:
    1  PackageChen;2 3 ImportJavax.xml.ws.Endpoint;4 5 ImportCom.hnu.cxf.ws.HelloWorld;6 ImportCom.hnu.cxf.ws.impl.HelloWorldWs;7 8  Public classServermain {9      Public Static voidMain (string[] args) {TenHelloWorld HW =NewHelloworldws (); One         //Call Endpoint's Publish method to publish the Web service, the first parameter is the Web Service service address, AEndpoint.publish ("Http://192.168.1.102:8081/hnu", HW); -SYSTEM.OUT.PRINTLN ("Web Service exposed successfully"); -     } the  -}

    At this point, the browser input http://192.168.1.102:8081/hnu?wsdl can appear stating that the exposure was successful.

Two. Develop Web servive client with CXF (new Java project name Ws_client)

    1. Call the Wsdl2java tool provided by CXF to generate the appropriate Java code based on the WSDL document. Any language implements a Web Service that needs to be provided and exposes a WSDL document.
    2. Find the class generated by Wsdl2java, a class that inherits (extends) the service, and an instance of that class can be used as a factory.
    3. Call the Getxxxport () method of an instance of the service subclass to return the Remote Web service proxy

Using CXF and spring to develop Web Service under MyEclipse

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.