Web Service (iv) manual publishing of the Web service Interface-CXF integration with spring

Source: Internet
Author: User
Tags soap wsdl

When we publish the Web service interface, there are two ways to invoke the Web Service service, one is through the dynamic client way, and the other is to reference the server interface, the way to refer to the service-side interface to the client-side coupling is relatively large, Instead of using WSDL, the client can call the server's method without knowing the service side exists.

Here is the project's structure diagram:

1.WEB Service Release Project



2. Write the service-side interface class and implementation class, as follows, an automatic publishing interface, one more annotations @webservice

Package Com.test.webservice;import Javax.jws.WebService, @WebServicepublic interface Ihelloworld {public String SayHello (user user);p ublic String sayHello1 ();}

Package Com.test.webservice;import Javax.jws.webmethod;import Javax.jws.WebService; @WebService (endpointinterface= "Com.test.webservice.IHelloWorld", Servicename= "helloService123") public class Helloworldimpl implements Ihelloworld {@Overridepublic String sayHello (user user) {System.out.println ("Start calling Web Service Method:sayhello ()"); return User.getusername () + "Lilongsheng";} @Override @webmethodpublic String sayHello1 () {System.out.println ("Start calling Web Service method:sayhello1 ()"); return " Lilongsheng1 ";}}
You can also add SOAP annotations above the implementation class, such as

@SOAPBinding (style = SOAPBinding.Style.DOCUMENT)
Represents the type, encoding, and other settings that the Web service method passes data to.

Reference: http://dlc-cdn.sun.com/jdk/jdk-api-localizations/jdk-api-zh-cn/publish/1.6.0/html/zh_CN/api/javax/jws/soap/ Soapbinding.html

3.Spring configuration file Configuration

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans"    Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"     xmlns:jaxws= "Http://cxf.apache.org/jaxws"    xsi: schemalocation= "Http://www.springframework.org/schema/beans                       http://www.springframework.org/schema/beans/ Spring-beans.xsd                       http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">                               <import Resource= "Classpath:meta-inf/cxf/cxf.xml"/>    <import resource= "classpath:meta-inf/cxf/ Cxf-extension-soap.xml "/>    <import resource=" Classpath:meta-inf/cxf/cxf-servlet.xml "/><JAXWS: Endpoint id= "helloService456" implementor= "Com.test.webservice.HelloWorldImpl" address= "/helloservice789"/> </beans>

4. Client-side test code

Package Com.test.webservice;//import Org.apache.cxf.endpoint.client;import Org.apache.cxf.endpoint.client;import Org.apache.cxf.jaxws.endpoint.dynamic.jaxwsdynamicclientfactory;public class TestClient {public static void main ( String[] args) {          jaxwsdynamicclientfactory DCF = Jaxwsdynamicclientfactory.newinstance ();          Create client Clients        = dcf.createclient ("http://192.168.24.82:8080/Web_Service_Spring/ws/helloService789?wsdl");          Object[] objects;          try {          user user=new User ();        User.setusername ("Longsheng");            objects = Client.invoke ("SayHello", user);              Output call result              System.out.println (objects[0].tostring ()),          } catch (Exception e) {              e.printstacktrace ();          }       }  }

The above parameters are passed as entities, and the entity needs to implement the serialization interface before it can be transmitted over the network. WEB service is used extensively between systems and system interactions.


Web Service (iv) manual publishing of the Web service Interface-CXF integration with spring

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.