gpt4 book ai didi

c# - C# : Invoke() function returns null 中的 PHP Web 服务

转载 作者:行者123 更新时间:2023-11-30 21:25:18 24 4
gpt4 key购买 nike

我在 .NET C# 中使用第三方 Web 服务时遇到问题。它在 Apache (NuSoap) 上运行。一切正常直到反序列化(可能......)。当我调用 SoapHttpClientProtocol.Invoke() 函数时,我总是得到一个包含一个空对象的对象数组。不好的是此 Web 服务不提供 WSDL 文档。 :-(

有人可以帮我吗?我认为,反序列化过程没有运行。

这是 soap 响应:

<?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; }
}

最佳答案

我解决了这个问题,但这并不容易。至少我学会了控制 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; }
}

关于c# - C# : Invoke() function returns null 中的 PHP Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/733303/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com