简体   繁体   English

从ASP.NET C#app中使用PHP Web服务(SOAP,WSDL) - 数组问题

[英]Consuming PHP webservice(SOAP, WSDL) from ASP.NET C# app - problems with array

I have a web service, defined(WSDL) and implemented in PHP. 我有一个Web服务,定义(WSDL)并在PHP中实现。 This one is relatively simple, important bits defined as the following: 这个是相对简单的,重要的位定义如下:

<message name='registerAccountRequest'>
        <part name='key' type='xsd:string'/> <!-- key -->
        <part name='data' type='xsd:array'/> <!-- account data -->
</message>
<message name='registerAccountResponse'>
        <part name='success' type='xsd:string' />
</message>

Note that data parameter is an array, in fact it is an associative array. 请注意,data参数是一个数组,实际上它是一个关联数组。 PHP client works beautifully with this, calling service and getting proper response. PHP客户端可以很好地工作,调用服务并获得适当的响应。

Now, when I try to consume this service with ASP.NET... what do I use as an associative array? 现在,当我尝试使用ASP.NET使用此服务时...我将如何用作关联数组? Hashtable?.. Proxy class created by Visual Studio says that second parameter is actually a string(or should be string) and not any type of collection... Hashtable?由Visual Studio创建的代理类表示第二个参数实际上是一个字符串(或应该是字符串)而不是任何类型的集合...

Quite puzzling... 相当令人费解......

Addendum: I tried grabbing SOAP request that PHP generates, here is a part of it that carries 'data' parameter: 附录:我尝试抓取PHP生成的SOAP请求,这里有一个带有'data'参数的部分:

...<data xsi:type="ns2:Map">
     <item>
       <key xsi:type="xsd:string">company_data</key>
       <value xsi:type="ns2:Map">
         <item>
           <key xsi:type="xsd:string">name</key>
           <value xsi:type="xsd:string">Test company name</value>
         </item>
         <item>
           <key xsi:type="xsd:string">slogan</key>
           <value xsi:type="xsd:string">Test company slogan</value>
         </item>

... So what data type that ns2:Map is? ...那么ns2:Map是什么数据类型? Is there something that ASP.NET supports that maps onto it cleanly? ASP.NET支持哪些内容可以干净地映射到它上面?

I ran into the same problem. 我遇到了同样的问题。 I'd created a web service in PHP and tried to consume it with ASP.NET. 我用PHP创建了一个Web服务,并尝试使用ASP.NET。 Making an associative array that ASP.NET could understand turned out to be tough. 制作一个ASP.NET可以理解的关联数组变得非常困难。 In the end, we decided to forgo the associative array in favor of an object. 最后,我们决定放弃关联数组以支持对象。

    <definitions
       ...
       xmlns:myNameSpace="http://myServer.com/mySoapService/files/schema">



    <types>
      <schema xmlns="http://www.w3.org/2001/XMLSchema"
          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
          targetNamespace="http://myServer.com/mySoapService/files/schema"
          xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">


      <complexType name="ViewCustomer_Object">
        <sequence>
            <element minOccurs="0" name="customer" type="string" />
            <element minOccurs="0" name="password" type="string" />
            <element minOccurs="0" name="first_name" type="string" />
        </sequence>
      </complexType>
    </schema>
  </types> 

   ...

    <message name="view_customer_response">
        <part name="return" type="myNameSpace:ViewCustomer_Object" />
    </message>



    ...

    </definitions>

The elements of the object are public properties. 对象的元素是公共属性。 Some might even argue that an object like this is just as good as a hashtable. 有些人甚至认为像这样的对象和散列表一样好。 Good luck. 祝好运。

Hashtable would be the most exact approximation of a PHP associative array... However, the best comparison for 'normal' use of an associative array would be a Dictionary<string, object> or perhaps even Dictionary<string, string> (depending on what your data actually is). Hashtable是PHP关联数组的最精确近似值...但是,关联数组的“正常”使用的最佳比较是Dictionary<string, object>或者甚至是Dictionary<string, string> (取决于你的数据实际上是什么)。

A Hashtable would fit that map nicely. Hashtable可以很好地适应该地图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM