Using axis in Java to publish and Invoke WebService

Source: Internet
Author: User

The WebService service needs to be called at work, and here's a record of how to publish and invoke WebService in Java.

Required JAR Packages:

Release WebService:
 PackageCom.xzh.webservice;ImportJavax.jws.WebMethod; ImportJavax.jws.WebService;Importjavax.xml.ws.Endpoint; @WebService Public classMyWebService { Publicstring Hello (string name) {System.out.println ("Hello:" +name); return"Hello:" +name; } @WebMethod (Exclude=true)       Publicstring Hello2 (string name) {System.out.println ("Hello2:" +name); return"Hello2:" +name; }       Public Static voidMain (string[] args) {/*** Parameter 1: Service's release address parameter 2: service's implementation*/Endpoint.publish ("Http://localhost:8080/transcode",NewMyWebService ()); System.out.println ("WebService Start Success"); }}

Visit WebService:
 PackageCom.xzh.webservice;Importjava.rmi.RemoteException;ImportJavax.xml.namespace.QName;ImportJavax.xml.rpc.ParameterMode;Importjavax.xml.rpc.ServiceException;ImportOrg.apache.axis.client.Call;ImportOrg.apache.axis.client.Service;ImportOrg.apache.axis.encoding.XMLType; Public classmywebclient { Public Static voidMain (string[] args) {Try {            //New One serviceService SV =NewService (); //Create a Call objectCall call =(call) Sv.createcall (); //set the interface address to invokeCall.settargetendpointaddress ("Http://localhost:8080/transcode"); //set the interface method to invokeCall.setoperationname (NewQName ("http://webservice.xzh.com/", "Hello")); //set parameters, when setting parameters, do not use the service-side defined parameter names, but arg0~argn to defineCall.addparameter ("arg0", xmltype.xsd_string, parametermode.in); //return Parameter typeCall.setreturntype (xmltype.xsd_string); Object result= Call.invoke (Newobject[]{"Jason"});        SYSTEM.OUT.PRINTLN (result); } Catch(serviceexception e) {e.printstacktrace (); } Catch(RemoteException e) {e.printstacktrace (); }    }}

log:

Using axis in Java to publish and Invoke 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.