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