请教:WebService中,怎样取得函数输出参数的返回值?

Ah 2003-09-16 08:02:02
我用VC写了一个COM
其中有一个方法类似于GetX(BSTR b1,BSTR* result),其中返回值由输出参数result返回。
我用java写的这个web service的客户端,远程调用已经成功了,但是我取不到返回的值,这个值应该是一个比较大的字符串
我的java客户端代码如下:
String result = null;
try {

QName qname = new QName(
"http://wynner/xxx/message/",
"GetX");
Service service = new Service();

Call call = (Call)service.createCall();
call.setTimeout(new Integer(120000));
call.setTargetEndpointAddress(
"http://wynner/xxx/DS.WSDL");
call.setUseSOAPAction(true);
call.setSOAPActionURI(
"http://wynner/xxx/DS/action/COMX.GetX");

call.setReturnType(
new QName("http://schemas.xmlsoap.org/soap/encoding/",
"string"),new Object().getClass());

call.addParameter("b1",qname,javax.xml.rpc.ParameterMode.IN);
call.addParameter("result",qname,javax.xml.rpc.ParameterMode.INOUT);

call.setOperationName(qname);

Object oParam[] = new Object[3];
oParam[0] = "xxx";
oParam[2] = "";
result = (String)call.invoke(oParam);
if(result.length() == 0) return null;
}
catch(Exception e) {
System.out.println(e.toString());
return null;
}




...全文
706 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
study_body 2003-09-19
  • 打赏
  • 举报
回复
客户端代码如下:
package com.bywang.app;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.encoding.*;
import javax.xml.namespace.QName;
import java.util.*;
import com.bywang.ws.holders.*;
import org.apache.axis.*;
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.encoding.Base64;
import org.apache.axis.handlers.BasicHandler;
import org.apache.axis.transport.http.HTTPConstants;
import org.apache.axis.utils.Messages;
import org.apache.axis.message.*;
//import javax.xml.soap.*;
import java.util.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.commons.logging.Log;

/**
* This class illustrates how to use the JAX-RPC API to invoke
* the Order Processing Web service dynamically
*/
public class testStringHolderClient {
public static void main(String[] args) throws Exception {
String targetNamespace = "http://generated.myservice.ws.bywang.com";
Service service = new Service();

Call call = (Call) service.createCall();
call.setTargetEndpointAddress("http://localhost:8080/axis/services/testStringHolder");
QName qnstrIn=new QName(targetNamespace,"in0");
QName qnstrInOut=new QName(targetNamespace,"in1");
QName operationName = new QName(targetNamespace, "testStringHolder");

call.setOperationName(operationName);
QName serviceName = new QName(targetNamespace,
"testStringHolder");

call.addParameter("strh",serviceName,ParameterMode.INOUT);



call.setReturnType( XMLType.XSD_STRING );
String test=new String("send a test string ");
String inoutStr=new String("send a inout string");
String str=(String)call.invoke( new Object[] {inoutStr} );
System.out.println(str);
Map outparams = call.getOutputParams();
if (outparams!=null)
{
Iterator ite=outparams.values().iterator();
if (ite.hasNext())
{
System.out.println((String)ite.next());
}
}
}
}
study_body 2003-09-19
  • 打赏
  • 举报
回复
给你我刚做的例子:
WSDL如下:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://generated.myservice.ws.bywang.com" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://generated.myservice.ws.bywang.com" xmlns:intf="http://generated.myservice.ws.bywang.com" 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:message name="testStringHolderRequest">

<wsdl:part name="in0" type="xsd:string"/>

<wsdl:part name="in1" type="xsd:string"/>

</wsdl:message>

<wsdl:message name="testStringHolderResponse">

<wsdl:part name="testStringHolderReturn" type="xsd:string"/>

<wsdl:part name="in1" type="xsd:string"/>

</wsdl:message>

<wsdl:portType name="HolderTest">

<wsdl:operation name="testStringHolder" parameterOrder="in0 in1">

<wsdl:input message="impl:testStringHolderRequest" name="testStringHolderRequest"/>

<wsdl:output message="impl:testStringHolderResponse" name="testStringHolderResponse"/>

</wsdl:operation>

</wsdl:portType>

<wsdl:binding name="testStringHolderSoapBinding" type="impl:HolderTest">

<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

<wsdl:operation name="testStringHolder">

<wsdlsoap:operation soapAction=""/>

<wsdl:input name="testStringHolderRequest">

<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://generated.myservice.ws.bywang.com" use="encoded"/>

</wsdl:input>

<wsdl:output name="testStringHolderResponse">

<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://generated.myservice.ws.bywang.com" use="encoded"/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

<wsdl:service name="HolderTestService">

<wsdl:port binding="impl:testStringHolderSoapBinding" name="testStringHolder">

<wsdlsoap:address location="http://localhost:8080/axis/services/testStringHolder"/>

</wsdl:port>

</wsdl:service>

</wsdl:definitions>
study_body 2003-09-19
  • 打赏
  • 举报
回复
我试过了,应该没有问题,不过嘛,AXIS非常奇怪,当我的服务端没有返回值,也就是说我只有一个INOUT类型的参数而返回值是void的时候呢,确实通过call.getOutputParams();取不到,而通过call.invoke的返回值得到的,如果函数远程webservice的一个方法有多个返回值,也就是说有一个INOUT类型的参数,并且有返回值,或者有多于一个的INOUT类型的参数才能通过call.getOutputParams();得到.
Ah 2003-09-19
  • 打赏
  • 举报
回复
另外,当
http://expert.csdn.net/Expert/TopicView1.asp?id=2277435

时也会出错
shipp 2003-09-19
  • 打赏
  • 举报
回复
UP
Ah 2003-09-19
  • 打赏
  • 举报
回复
返回的SOAP消息如下:
很明显,调用成功了,但是就是取不到out的值

HTTP/1.1 200 OK

Server: Microsoft-IIS/5.0

Date: Fri, 19 Sep 2003 01:02:31 GMT

X-Powered-By: ASP.NET

Content-Type: text/xml; charset="UTF-8"

Content-Length: 367

Expires: -1;



<?xml version="1.0" encoding="UTF-8" standalone="no"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAPSDK1:GetInputResponse xmlns:SOAPSDK1="http://wynner/SCT/message/"><out>abcdefg</out></SOAPSDK1:GetInputResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Ah 2003-09-19
  • 打赏
  • 举报
回复
不好意思,上面的那个WSDL错了,应该是这个才对.
<?xml version='1.0' encoding='UTF-8' ?>
<definitions
name='SCT'
targetNamespace='http://wynner/SCT/wsdl/'
xmlns:wsdlns='http://wynner/SCT/wsdl/'
xmlns:typens='http://wynner/SCT/type/'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:stk='http://schemas.microsoft.com/soap-toolkit/wsdl-extension'
xmlns:dime='http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/'
xmlns:ref='http://schemas.xmlsoap.org/ws/2002/04/reference/'
xmlns:content='http://schemas.xmlsoap.org/ws/2002/04/content-type/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>

<types>
<schema
targetNamespace='http://wynner/SCT/type/'
xmlns='http://www.w3.org/2001/XMLSchema'
xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
elementFormDefault='qualified'>

<import namespace='http://schemas.xmlsoap.org/soap/encoding/'/>
<import namespace='http://schemas.xmlsoap.org/wsdl/'/>
<import namespace='http://schemas.xmlsoap.org/ws/2002/04/reference/'/>
<import namespace='http://schemas.xmlsoap.org/ws/2002/04/content-type/'/>

</schema>
</types>

<message name='Speaker.GetMax'>
<part name='a' type='xsd:int'/>
<part name='b' type='xsd:int'/>
</message>

<message name='Speaker.GetMaxResponse'>
<part name='rst' type='xsd:int'/>
</message>

<message name='Speaker.GetInput'>
<part name='in' type='xsd:string'/>
</message>

<message name='Speaker.GetInputResponse'>
<part name='out' type='xsd:string'/>
</message>

<portType name='SpeakerSoapPort'>

<operation name='GetMax' parameterOrder='a b rst'>
<input message='wsdlns:Speaker.GetMax'/>
<output message='wsdlns:Speaker.GetMaxResponse'/>
</operation>

<operation name='GetInput' parameterOrder='in out'>
<input message='wsdlns:Speaker.GetInput'/>
<output message='wsdlns:Speaker.GetInputResponse'/>
</operation>

</portType>

<binding name='SpeakerSoapBinding' type='wsdlns:SpeakerSoapPort' >

<stk:binding preferredEncoding='UTF-8'/>
<soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>

<operation name='GetMax'>
<soap:operation soapAction='http://wynner/SCT/action/Speaker.GetMax'/>
<input>
<soap:body
use='encoded'
namespace='http://wynner/SCT/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
parts='a b'/>
</input>
<output>
<soap:body
use='encoded'
namespace='http://wynner/SCT/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
parts='rst'/>
</output>
</operation>

<operation name='GetInput'>
<soap:operation soapAction='http://wynner/SCT/action/Speaker.GetInput'/>
<input>
<soap:body
use='encoded'
namespace='http://wynner/SCT/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
parts='in'/>
</input>
<output>
<soap:body
use='encoded'
namespace='http://wynner/SCT/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
parts='out'/>
</output>
</operation>

</binding>

<service name='SCT' >
<port name='SpeakerSoapPort' binding='wsdlns:SpeakerSoapBinding' >
<soap:address location='http://wynner/sct/SCT.WSDL'/>
</port>
</service>

</definitions>
Ah 2003-09-19
  • 打赏
  • 举报
回复
搞定乐!
原来要把INOUT换成IN !!???
简直是太莫名奇妙了!
study_body 2003-09-18
  • 打赏
  • 举报
回复
怎么只有我一个人,高手呢?
study_body 2003-09-18
  • 打赏
  • 举报
回复
我想可能是我的输出参数 BSTR* result 是一个二级指针,所以Java不认识?

我觉得不是,因为他与客户端可以说是一点关系也没有啊,java关心的是怎样构造一个soap消息吧!目前AXIS支持的java bean同复杂类型的映射,更支持多维数组,因此我觉得在你的问题中应该不存在这个问题(我觉得).
study_body 2003-09-18
  • 打赏
  • 举报
回复
我玩的时候都是用java写的webservice不过用什么写应该没有关系啊.
看你的wsdl文档的消息部分全都是xsd:int啊,我知道的不多,还是请高人指导吧.
com我不懂,二级指针我更不懂,如果能贴出你用vc调用返回的soap消息就很清楚了.
Ah 2003-09-18
  • 打赏
  • 举报
回复
我的WSDL内容如下

<?xml version='1.0' encoding='UTF-8' ?>
<definitions
name='SCT'
targetNamespace='http://wynner/SCT/wsdl/'
xmlns:wsdlns='http://wynner/SCT/wsdl/'
xmlns:typens='http://wynner/SCT/type/'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:stk='http://schemas.microsoft.com/soap-toolkit/wsdl-extension'
xmlns:dime='http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/'
xmlns:ref='http://schemas.xmlsoap.org/ws/2002/04/reference/'
xmlns:content='http://schemas.xmlsoap.org/ws/2002/04/content-type/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>

<types>
<schema
targetNamespace='http://wynner/SCT/type/'
xmlns='http://www.w3.org/2001/XMLSchema'
xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
elementFormDefault='qualified'>

<import namespace='http://schemas.xmlsoap.org/soap/encoding/'/>
<import namespace='http://schemas.xmlsoap.org/wsdl/'/>
<import namespace='http://schemas.xmlsoap.org/ws/2002/04/reference/'/>
<import namespace='http://schemas.xmlsoap.org/ws/2002/04/content-type/'/>

</schema>
</types>

<message name='Speaker.GetMax'>
<part name='a' type='xsd:int'/>
<part name='b' type='xsd:int'/>
</message>

<message name='Speaker.GetMaxResponse'>
<part name='result' type='xsd:int'/>
</message>

<portType name='SpeakerSoapPort'>

<operation name='GetMax' parameterOrder='a b result'>
<input message='wsdlns:Speaker.GetMax'/>
<output message='wsdlns:Speaker.GetMaxResponse'/>
</operation>

</portType>

<binding name='SpeakerSoapBinding' type='wsdlns:SpeakerSoapPort' >

<stk:binding preferredEncoding='UTF-8'/>
<soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>

<operation name='GetMax'>
<soap:operation soapAction='http://wynner/SCT/action/Speaker.GetMax'/>
<input>
<soap:body
use='encoded'
namespace='http://wynner/SCT/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
parts='a b'/>
</input>
<output>
<soap:body
use='encoded'
namespace='http://wynner/SCT/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
parts='result'/>
</output>
</operation>

</binding>

<service name='SCT' >
<port name='SpeakerSoapPort' binding='wsdlns:SpeakerSoapBinding' >
<soap:address location='http://wynner/sct/SCT.WSDL'/>
</port>
</service>

</definitions>
Ah 2003-09-18
  • 打赏
  • 举报
回复
另外,我用VC写的客户端也调用成功了

我想可能是我的输出参数 BSTR* result 是一个二级指针,所以Java不认识?

可是这个二级指针是一个标准的字符串啊
Ah 2003-09-18
  • 打赏
  • 举报
回复
我的QName是这样的呀,有什么问题吗?
QName qname = new QName(
"http://wynner/xxx/message/",
"GetX");

Ah 2003-09-17
  • 打赏
  • 举报
回复
TO study_body(珍惜每一天):
GetX(BSTR b1,BSTR* result)的第二个参数是一个输出参数,参数类型为字符串
WSDL中的描述是类型描述是 xsd:string
另外,qname我不太明白你的意思,这些参数都是在同一名字空间下的.

to junnef(光明圣堂武士):
你说的这些我都试过了,还是不行.


另外:
我用VC和VB又各写了一个客户端,其中VB的调用和返回都是成功的.
study_body 2003-09-17
  • 打赏
  • 举报
回复
addParameter
public void addParameter(QName paramName,
QName xmlType,
ParameterMode parameterMode)Adds the specified parameter to the list of parameters for the operation associated with this Call object. Note: Not part of JAX-RPC specification.

Parameters:
paramName - Name that will be used for the parameter in the XML
xmlType - XMLType of the parameter
parameterMode - one of IN, OUT or INOUT

其中xmlType是参数的XMLType ,而不是操作方法的XMLType 吧,不知道我说的对不对
study_body 2003-09-17
  • 打赏
  • 举报
回复
addParameter
public void addParameter(QName paramName,
QName xmlType,
ParameterMode parameterMode)Adds the specified parameter to the list of parameters for the operation associated with this Call object. Note: Not part of JAX-RPC specification.

Parameters:
paramName - Name that will be used for the parameter in the XML
xmlType - XMLType of the parameter
parameterMode - one of IN, OUT or INOUT

其中xmlType是参数的XMLType ,而不是操作方法的XMLType 吧,不知道我说的对不对
study_body 2003-09-17
  • 打赏
  • 举报
回复
说一句实话,我都是自己学的,所以可能理解有问题.
call.addParameter("b1",qname,javax.xml.rpc.ParameterMode.IN);
qname不是对应你的远程service的GetX方法的某个参数嘛?


call.addParameter("result",qname,javax.xml.rpc.ParameterMode.INOUT);

更改成

QName serviceName = new QName("http://wynner/xxx/message/",yourservicename);
call.addParameter("result",serviceName,javax.xml.rpc.ParameterMode.INOUT);

另外再说两句,你的service的方法的参数的名字是result,好像soap将函数的返回值默认的名字为result不知道这会不会导致冲突,不过你能够用其他客户端实现,说明你的
service没有问题,能贴出你用其他客户端测试成功后返回的soap消息吗?


Ah 2003-09-16
  • 打赏
  • 举报
回复
错误信息如下:
org.xml.sax.SAXException: Deserializing parameter 'result': could not find deserializer for type {http://wynner/xxx/ds/message/}GetX
junnef 2003-09-16
  • 打赏
  • 举报
回复
你那个result定义的时候应该这样吧,String result="";或者String result=new String(""); null是非序列化对象。
加载更多回复(3)

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧