0

当我尝试通过网络方法检索信息时遇到问题。我正在使用代理来调用 Web 服务,在该代理中我有一个使用“out”参数返回数据的操作。

服务器成功执行操作,返回正确实例化的参数(我还使用流量分析器检查了soap返回消息并且没问题),但是当我向代理请求这些参数时,我只获得空值。

这是一些代码信息:

//这是使用代理对web服务的调用(t是代理,get_capabilities是webmethod)

public trf_capabilities get_capabilities() {
            trf_capabilities trfcap = new trf_capabilities();                
            trfcap.protocol_list= t.get_capabilities(0, out trfcap.pause, out trfcap.maxfiles, out trfcap.maxsize, out trfcap.encrypt, out trfcap.authenticate, out trfcap.integritycheck, out  trfcap.hashtype, out  trfcap.multipath, out  trfcap.profile_list);            
            return trfcap;
        }

//这是webMethod定义

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("iTransfer-get_capabilities",/*RequestElementName="elementoVacio_",*/ RequestNamespace="", ResponseElementName="trf_capabilitiesPar", ResponseNamespace="", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        [return: System.Xml.Serialization.XmlElementAttribute("protocol_list", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public protocolType[] get_capabilities([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] int vacio, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] out bool pause, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] out uint maxfiles, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] out uint maxsize, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] out bool encrypt, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] out bool authenticate, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] out bool integritycheck, [System.Xml.Serialization.XmlElementAttribute("hash_type", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] out hash_typeType[] hash_type, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] out bool multipath, [System.Xml.Serialization.XmlElementAttribute("profile_list", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] out profile_listType[] profile_list) {
            object[] results = this.Invoke("get_capabilities", new object[] {
                        vacio});
            pause = ((bool)(results[1]));
            maxfiles = ((uint)(results[2]));
            maxsize = ((uint)(results[3]));
            encrypt = ((bool)(results[4]));
            authenticate = ((bool)(results[5]));
            integritycheck = ((bool)(results[6]));
            hash_type = ((hash_typeType[])(results[7]));
            multipath = ((bool)(results[8]));
            profile_list = ((profile_listType[])(results[9]));
            return ((protocolType[])(results[0]));
        }

如您所见,我在调用和处理程序方法中都使用了“out”标记,但这似乎不足以获得正确的行为。

最后,这是流量分析器截获的 SOAP 消息:

Content-Type: text/xml; charset=UTF-8
Server: SOAPStandaloneServer
Content-Length: 584
Connection: close

<E:Envelope xmlns:E="http://schemas.xmlsoap.org/soap/envelope/" xmlns:A="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.w3.org/2001/XMLSchema"><E:Body><ns1:get_capabilitiesResponse xmlns:ns1=""><ns1:pause>true</ns1:pause><ns1:maxfiles>5</ns1:maxfiles><ns1:maxsize>0</ns1:maxsize><ns1:encrypt>true</ns1:encrypt><ns1:authenticate>true</ns1:authenticate><ns1:integritycheck>true</ns1:integritycheck><ns1:multipath>true</ns1:multipath></ns1:get_capabilitiesResponse></E:Body></E:Envelope>

有任何想法吗?

4

2 回答 2

1

我认为您在 [decoration] 和序列化答案方面走在了正确的轨道上。那里的数组似乎有点棘手,你有其中元素的序列化例程吗?

再说一次,拥有这么多的输出参数似乎有点压倒性。我可能会创建一个“ServiceResponse”结构并将所有参数作为属性添加到其中。

编辑:下一步,如果响应看起来不错但代理在反序列化它时遇到问题,我建议(当然)深入研究代理。代理是生成的还是您手动编写的?尝试单步执行它,看看它试图用给定的参数做什么。我经常使用 Web 服务,直到我的眼睛流血,才发现反序列化规范已经过时了。

于 2010-07-05T12:00:00.143 回答
0

我发现了所有这一切的有趣之处。我一直在检查我拥有的两种 Web 方法的标题(一种是我必须使用的 C++ 编写的,另一种是我用 C# 开发的测试方法)。我意识到,对于输出参数,.NET 添加了某种包装。下面是msdn的解释:

SOAP 响应的 XML 部分封装了Web 服务方法的输出参数,包括元素内的结果。默认情况下,封装元素的名称是附加了 Response 的 Web 服务方法的名称。

链接在这里

看来您必须使用该包装器才能使“输出”参考参数正常工作。

于 2010-07-05T14:10:26.240 回答