我在.NET C#中使用第三方Web服务时遇到问题。它运行在Apache(NuSoap)上。一切正常,直到反序列化(可能......)。当我调用SoapHttpClientProtocol.Invoke()
函数时,我总是得到一个带有一个空对象的对象数组。不好的是,这个Web服务不提供WSDL文档。 :-(
有人可以帮助我吗?我认为,反序列化过程不会运行。
这是肥皂反应:
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:EncodingTestResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/">
<item xmlns:ns4071="http://xml.apache.org/xml-soap" xsi:type="ns4071:Map">
<item>
<key xsi:type="xsd:string">ascii</key>
<value xsi:type="xsd:string">ertzyuuioasdcnERSTZYUIOADCN</value>
</item>
<item>
<key xsi:type="xsd:string">latin2</key>
<value xsi:type="xsd:string">xy</value>
</item>
<item>
<key xsi:type="xsd:string">w1250</key>
<value xsi:type="xsd:string">pq</value>
</item>
</item>
</ns1:EncodingTestResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
通话方式:
[SoapTrace]
[SoapDocumentMethod("EncodingTest",ParameterStyle=SoapParameterStyle.Wrapped)]
public item EncodingTest()
{
var obj = this.Invoke("EncodingTest", new object[] {});
return null;
}
和我试图反序列化的对象:
[Serializable]
[XmlType(Namespace = "http://xml.apache.org/xml-soap", TypeName="item")]
public class item
{
[XmlArray("item", Form = XmlSchemaForm.Unqualified)]
public item[] items { get; set; }
[XmlElement(Form=XmlSchemaForm.Unqualified)]
public string key { get; set; }
[XmlElement(Form = XmlSchemaForm.Unqualified)]
public string value { get; set; }
}
答案 0 :(得分:4)
我解决了这个问题,但这并不容易。至少我学会了控制xml反序列化.. :))
[SoapDocumentMethod(ResponseElementName = "EncodingTestResponse", ResponseNamespace = "http://schemas.xmlsoap.org/soap/envelope/")]
[return: XmlArray("item", Namespace = "", IsNullable = false)]
[SoapTrace]
public item[] EncodingTest()
{
object[] result = this.Invoke("EncodingTest", new object[] { });
return (item[])result[0];
}
[SoapType(TypeName = "Map", Namespace = "http://xml.apache.org/xml-soap")]
public class item
{
[XmlElement(Form = XmlSchemaForm.Unqualified)]
public string key { get; set; }
[XmlElement(Form = XmlSchemaForm.Unqualified)]
public string value { get; set; }
public item[] items { get; set; }
}