新知识补充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;
}

}

wsdl文档:
<?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.4
Built 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 block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值