新知识补充WebService----实现多个返回值的办法
业务需求需要实现web service的方法能返回多个返回值,查阅了下axis的user guilde,实现起来其实很简单.
axis里面有多个类型的持有类比如StringHolder类等,我们只需要把传入的参数改为对应类型的持有类就可以了.
下面是我的例子:
实现类
public class NumwireserviceforCRMSoapBindingImpl implements com.geosoft.numwire.webservice.server.toCRM.NumwireServiceForCRM{ public int asiainfo__ResQueryCustomerId(java.lang.String in0, javax.xml.rpc.holders.StringHolder in1) throws java.rmi.RemoteException { in1.value="1212121"; return -3; }}
<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions targetNamespace="urn:numwireservice" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:numwireservice" xmlns:intf="urn:numwireservice" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><!--WSDL created by Apache Axis version: 1.4Built on Apr 22, 2006 (06:55:48 PDT)--> <wsdl:message name="asiainfo__ResQueryCustomerIdRequest"> <wsdl:part name="in0" type="soapenc:string"/> <wsdl:part name="in1" type="soapenc:string"/> </wsdl:message> <wsdl:message name="asiainfo__ResQueryCustomerIdResponse"> <wsdl:part name="asiainfo__ResQueryCustomerIdReturn" type="xsd:int"/> <wsdl:part name="in1" type="soapenc:string"/> </wsdl:message> <wsdl:portType name="NumwireServiceForCRM"> <wsdl:operation name="asiainfo__ResQueryCustomerId" parameterOrder="in0 in1"> <wsdl:input message="impl:asiainfo__ResQueryCustomerIdRequest" name="asiainfo__ResQueryCustomerIdRequest"/> <wsdl:output message="impl:asiainfo__ResQueryCustomerIdResponse" name="asiainfo__ResQueryCustomerIdResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="numwireserviceforCRMSoapBinding" type="impl:NumwireServiceForCRM"> <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="asiainfo__ResQueryCustomerId"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="asiainfo__ResQueryCustomerIdRequest"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:numwireservice" use="encoded"/> </wsdl:input> <wsdl:output name="asiainfo__ResQueryCustomerIdResponse"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:numwireservice" use="encoded"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="NumwireServiceForCRMService"> <wsdl:port binding="impl:numwireserviceforCRMSoapBinding" name="numwireserviceforCRM"> <wsdlsoap:address location="http://localhost:8080/services/numwireserviceforCRM"/> </wsdl:port> </wsdl:service></wsdl:definitions>
import java.net.MalformedURLException;import java.net.URL;import java.rmi.RemoteException;import javax.xml.rpc.ServiceException;import javax.xml.rpc.holders.StringHolder;import com.geosoft.numwire.webservice.server.toCRM.NumwireServiceForCRMServiceLocator;import com.geosoft.numwire.webservice.server.toCRM.NumwireserviceforCRMSoapBindingStub;public class TestMultyReturn {public static void main(String[] args) {NumwireServiceForCRMServiceLocator forCRMServiceLocator=new NumwireServiceForCRMServiceLocator();NumwireserviceforCRMSoapBindingStub bindingStub=null;try {java.net.URL url=new URL("/*你的服务部署的url*/");bindingStub=(NumwireserviceforCRMSoapBindingStub) forCRMServiceLocator.getnumwireserviceforCRM(url);String in0="aaaaa";StringHolder in1=new StringHolder("sdsds");bindingStub.asiainfo__ResQueryCustomerId(in0, in1);System.out.println(in1.value);//打印出来的是改变后的值} catch (MalformedURLException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (ServiceException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (RemoteException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}