PHP Web服务在C#:调用()函数返回null [英] PHP Web Service in C# : Invoke() function returns null

查看:116
本文介绍了PHP Web服务在C#:调用()函数返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.NET中使用C#耗费了第三方Web服务的问题。它运行在Apache(的NuSOAP)。一切都正常工作达反序列化(可能是...)。当我打电话 SoapHttpClientProtocol.Invoke()函数,我总是得到一个空对象的对象数组。坏的是,这种网络服务不提供WSDL文档。 :-(

任何人可以帮助我,好吗?我认为,反序列化过程中不运行。

下面是SOAP响应:

 < XML版本=1.0编码=ISO-8859-1&GT?;
< SOAP-ENV:信封SOAP-ENV:encodingStyle的=htt​​p://schemas.xmlsoap.org/soap/encoding/的xmlns:SOAP-ENV =htt​​p://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:身体与GT;
    < NS1:EncodingTestResponse的xmlns:NS1 =htt​​p://schemas.xmlsoap.org/soap/envelope/>

      <项目的xmlns:ns4071 =htt​​p://xml.apache.org/xml-soap的xsi:type =ns4071:地图>
        <项目>
          <关键的xsi:type =XSD:字符串> ASCII< /键>
          <值的xsi:type =XSD:字符串> ertzyuuioasdcnERSTZYUIOADCN< /值GT;
        < /项目>
        <项目>
          <关键的xsi:type =XSD:字符串>拉丁文2< /键>
          <值的xsi:type =XSD:字符串> XY< /值GT;
        < /项目>
        <项目>
          <关键的xsi:type =XSD:字符串> W1250< /键>
          <值的xsi:type =XSD:字符串> PQ< /值GT;
        < /项目>
      < /项目>

    < / NS1:EncodingTestResponse>
  < / SOAP-ENV:身体与GT;
< / SOAP-ENV:信封>
 

调用方式:

  [SoapTrace]
[SoapDocumentMethod(EncodingTest,ParameterStyle = SoapParameterStyle.Wrapped)
公共项目EncodingTest()
{
    VAR OBJ = this.Invoke(EncodingTest,新的对象[] {});
    返回null;
}
 

和对象,而我试图反序列化:

  [Serializable接口]
[XmlType将(命名空间=htt​​p://xml.apache.org/xml-soap,类型名=项目)
公共类项目
{
[XmlArray(项目,表= XmlSchemaForm.Unqualified)
公共项目[] {项目获取;组; }

[的XmlElement(表= XmlSchemaForm.Unqualified)
公共字符串键{获得;组; }

[的XmlElement(表= XmlSchemaForm.Unqualified)
公共字符串值{获得;组; }
}
 

解决方案

我解决这个问题,但它是不容易的。至少我学会controling XML序列化..:)

  [SoapDocumentMethod(ResponseElementName =EncodingTestResponse,ResponseNamespace =htt​​p://schemas.xmlsoap.org/soap/envelope/)
[返回:XmlArray(项目,命名空间=,ISNULLABLE = FALSE)]
[SoapTrace]
公共项目[] EncodingTest()
{
    [对象]结果= this.Invoke(EncodingTest,新的对象[] {});
    返程(项目[])结果[0];
}


[SoapType(类型名=地图,命名空间=htt​​p://xml.apache.org/xml-soap)
    公共类项目
    {
    [的XmlElement(表= XmlSchemaForm.Unqualified)
    公共字符串键{获得;组; }

    [的XmlElement(表= XmlSchemaForm.Unqualified)
    公共字符串值{获得;组; }

    公共项目[] {项目获取;组; }
    }
 

I have a problem with consuming a third-party web service in .NET C#. It runs on Apache (NuSoap). Everything works normally up to deserialization (probably...). When I call the SoapHttpClientProtocol.Invoke() function, I always get an object array with one null object. Bad is that this web service doesn't provide a WSDL document. :-(

Can anybody help me, please? I think, that the deserialization process doesn't run.

Here is soap response:

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

Calling method:

[SoapTrace]
[SoapDocumentMethod("EncodingTest",ParameterStyle=SoapParameterStyle.Wrapped)]
public item EncodingTest()
{
    var obj = this.Invoke("EncodingTest", new object[] {});
    return null;
}

and the object, which I was trying to deserialize:

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

解决方案

I solve this, but it wasn't easy. At least i learned controling xml deserialization.. :)

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

这篇关于PHP Web服务在C#:调用()函数返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆