我嘗試通過web方法檢索信息時遇到問題。我正在使用代理來調用Web服務,在該代理中我有一個操作,它使用'out'參數返回數據。在webmethod中使用引用參數的ASP.NET web服務
服務器成功執行操作,正確返回參數實例(我也使用流量分析器檢查了soap返回消息並且沒問題),但是當我向代理請求這些參數時,我只獲得null值。
下面是一些代碼信息:
//這是調用使用代理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]));
}
正如你所看到的,我使用的兩個呼叫和處理方法的「出」的道理,但似乎還不足以得到正確的行爲。
最後,這裏是與交通分析截獲的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>
任何想法?
我剛剛使用'out'參數傳遞數據並正常工作,並使用另一個webservice進行測試。我打賭到xml序列化和[裝飾]。我不知道還有什麼可以的。 – Francisco 2010-07-05 10:54:59
另一個值得考慮的是我無法獲得webmethod的正確實例返回值。 – Francisco 2010-07-06 08:15:30