WebService simple to use

Source: Internet
Author: User
Tags wsdl

I. WebService Publishing Service mode

Way one: Use the JRE itself to provide the way Jax-ws

1) Add annotations on the class or on the interface or abstract class of the corresponding class @webservice

2) Release service Endpoint.publish ("Http://127.0.0.1:8800/hello", New Helloserviceimpl ());

3) http://127.0.0.1:8800/hello?wsdl can display instructions to publish the service successfully

Method Two: Publish the service using the CXF method

1) need to introduce the appropriate jar package

        <Dependency>            <groupId>Org.apache.cxf</groupId>            <Artifactid>Cxf-rt-frontend-jaxws</Artifactid>            <version>2.2.3</version>        </Dependency>        <Dependency>            <groupId>Org.apache.cxf</groupId>            <Artifactid>Cxf-rt-transports-http</Artifactid>            <version>2.2.3</version>        </Dependency>        <Dependency>            <groupId>Org.apache.cxf</groupId>            <Artifactid>Cxf-rt-transports-http-jetty</Artifactid>            <version>2.2.3</version>        </Dependency>
CXF the jar to be introduced by the Publishing Service

2) Add annotations on the class or on the interface or abstract class of the corresponding class @webservice

3) Release service Endpoint.publish ("Http://127.0.0.1:8800/hello", New Helloserviceimpl ());

4) HTTP://127.0.0.1:8800/HELLO?WSDL can display a description of the Publish service success and the way the WSDL document generated is not quite the same.

Two. WebService Invoke service mode

Mode one: Use the JRE itself to provide a way Jax-WS can be used for any situation

A. Select New Web Service Client

    

B. Enter the WSDL address and click Finish

C. Calling the generated code

1. How to use proxies

        New wsserverproxy ();         = Wsserverproxy.execbusinessmethod ("nice", "123213");        System.out.println (Execbusinessmethod);    
Proxy mode call service side

2. How to use the interface

       // Note that the interface should be consistent with the service-side annotations @[email protected]         New // WSDL document address        for the service QName qname=New//wsdl on targetnamespace, and the value of the following name        Service service=  Service.create (URL, QName);        WSServer Ms=service.getport (wsserver.  Class);         = Ms.execbusinessmethod ("Good", "123123");        System.out.println (hello);    
interface mode call service side

Mode two: The use of the Axis method call can only be cxf the way of service delivery

A. The jar to be referenced

<!--referenced jar package--><!--https://Mvnrepository.com/artifact/axis/axis --<dependency> <groupId>axis</groupId> <artifactId>axis</artifactId> < Version>1.4</version> </dependency> <!--https://Mvnrepository.com/artifact/javax.mail/javax.mail-api --<dependency> <groupId>javax.mail</groupId> <artifactid>javax.mail-api</artifactid > <version>1.5.5</version> </dependency> <!--https://mvnrepository.com/artifact/javax.activation/activation --<dependency> <groupId>javax.activation</groupId> <artifactid>activation</artifact Id> <version>1.1</version> </dependency>
the jar that axis invokes the service to reference

B. Calling the service code note that the package does not get wrong

Importjava.net.MalformedURLException;ImportJava.net.URL;Importjava.rmi.RemoteException;ImportJavax.xml.namespace.QName;Importjavax.xml.rpc.ServiceException;ImportOrg.apache.axis.client.Call;ImportOrg.apache.axis.client.Service; //New One serviceService SV =NewService (); //Create a Call objectCall call =(call) Sv.createcall (); //set the interface address to invokeCall.settargetendpointaddress (NewURL ("Http://127.0.0.1:8899/hello")); //set the interface method to invokeCall.setoperationname (NewQName ("Gethello")); //Set parameter The second argument represents a string type, and the third parameter represents the entry parameterCall.addparameter ("str", org.apache.axis.encoding.xmltype.xsd_string,javax.xml.rpc.parametermode.in); //return Parameter typeCall.setreturntype (Org.apache.axis.encoding.XMLType.XSD_STRING); //starts calling the method and returns the appropriate data information, returned in an XML-formatted string, or in JSON format, primarily to see how the other party returnsObject result = Call.invoke (Newobject[]{"Nice"}); SYSTEM.OUT.PRINTLN (result);//Print a string
Invoking the service code

   

    

    

WebService simple to use

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.