One day, a variety of ways to generate webservice, is for node. js to communicate smoothly with the program. Finally, the Axis2 succeeded. The work has basically been completed and can now be summed up.
About the way of generation, it is recommended to use Eclipse, more convenient, specific ways, the last post has been reproduced, AXIS2 and cxf2.x are so. Note: Not on the project new one webservice, is on the new one that you want to call the class as WebService.
The specific code, and the test code, are passed the test.
First, Axis2
Service side:
Package Cn.wang; Public class Eventforwarder { public string Send (String message) { return "Hello word" +message;} }
When the client calls the Send method, it returns to them a string that we spell.
Client:
Packagecn.test;ImportJavax.xml.namespace.QName;ImportOrg.apache.axis2.AxisFault;Importorg.apache.axis2.addressing.EndpointReference;Importorg.apache.axis2.client.Options;Importorg.apache.axis2.rpc.client.RPCServiceClient; Public classClient { Public Static voidMain (string[] args)throwsAxisfault {rpcserviceclient serviceclient=Newrpcserviceclient (); Options Options=serviceclient.getoptions (); EndpointReference Targetepr=NewEndpointReference ("Http://localhost:8080/WebService/services/HelloWorld"); This writes itself the generated WebService address Options.setto (TARGETEPR); object[] Send=Newobject[]{"zzz"};//The type of sendClass[] Recevied=NewClass[]{string.class};//The result type of recevedQName qname=NewQName ("http://wang.cn", "Send"); String result=serviceclient.invokeblocking (QName, send, recevied) [0]; SYSTEM.OUT.PRINTLN (result); }}
Second, CXF 2.x
This comparison is close to the standard.
Service side:
Interface:
PackageCom.gnivcode.spms.process.service;ImportJavax.jws.WebMethod;ImportJavax.jws.WebParam;ImportJavax.jws.WebResult;ImportJavax.jws.WebService; @WebService (targetnamespace= "http://service.process.spms.gnivcode.com/") Public Interfaceeventforwarderinterface {@WebMethod (OperationName= "Send") @WebResult (name= "Feedresult") PublicFeedresult Send (@WebParam (name= "Nocpacket", targetnamespace= "http://service.process.spms.gnivcode.com/") Nocpacket nocpacket); @WebMethod (OperationName= "Process") @WebResult (name= "Feedresult") PublicFeedresult process (@WebParam (name= "Eventpacket", targetnamespace= "http://service.process.spms.gnivcode.com/") Eventpacket eventpacket);}
PackageCom.gnivcode.spms.process.service;ImportJavax.jws.WebMethod;ImportJavax.jws.WebParam;ImportJavax.jws.WebService; @WebService (targetnamespace= "http://service.process.spms.gnivcode.com/", PortName = "Eventforwarderport", ServiceName = "Eventforwarderservice") Public classEventforwarderImplementseventforwarderinterface{ PublicFeedresult process (@WebParam (name = "Eventpacket")) Eventpacket eventpacket) {Feedresult Feedresult=NewFeedresult (); Feedresult.setresultdesc ("Hi,feedresult"); returnFeedresult; } PublicFeedresult Send (@WebParam (name = "Nocpacket")) Nocpacket nocpacket) {Feedresult Feedresult=NewFeedresult (); Feedresult.setresultdesc ("Hi,feedresult"); returnFeedresult; } }
Do not use the interface can also, and the same as above, the specific also forgotten.
Client:
Packagecn.wang.test;ImportOrg.apache.cxf.jaxws.JaxWsProxyFactoryBean;ImportCom.gnivcode.spms.process.service.EventForwarderInterface;ImportCom.gnivcode.spms.process.service.FeedResult;ImportCom.gnivcode.spms.process.service.NocPacket; Public classClient { Public Static voidMain (string[] args) {//TODO auto-generated Method StubJaxwsproxyfactorybean factory=NewJaxwsproxyfactorybean (); Factory.setserviceclass (eventforwarderinterface.class); Factory.setaddress ("Http://localhost:8080/MessageProcess/services/EventForwarderPort"); Eventforwarderinterface Eventforwarderinterface=(Eventforwarderinterface) factory.create (); Nocpacket Nocpacket=NewNocpacket (); Nocpacket.setgwname ("Noc_gwname"); Feedresult Feedresult=eventforwarderinterface.send (Nocpacket); System.out.println ("Feedresult desc:" +Feedresult.getresultdesc ()); System.out.println ("Feedresult Code:" +Feedresult.getresultcode ()); }}