代码之家  ›  专栏  ›  技术社区  ›  Alex N.

从ASP.NET C#应用程序使用PHP Web服务(SOAP、WSDL)-数组问题

  •  4
  • Alex N.  · 技术社区  · 17 年前

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

    请注意,数据参数是一个数组,实际上它是一个关联数组。 PHP客户端可以很好地处理这个问题,调用服务并获得正确的响应。

    现在,当我尝试使用ASP.NET使用此服务时。。。我使用什么作为关联数组?哈希表?。。VisualStudio创建的代理类表示第二个参数实际上是字符串(或者应该是字符串),而不是任何类型的集合。。。

    相当令人费解。。。

    增编: 我尝试抓取PHP生成的SOAP请求,其中一部分包含“数据”参数:

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

    ...

    2 回复  |  直到 17 年前
        1
  •  2
  •   Nick R.    17 年前

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

    对象的元素是公共属性。有些人甚至会争辩说,像这样的对象和哈希表一样好。祝你好运

        2
  •  1
  •   Matthew Scharley    17 年前

    Hashtable 将是PHP关联数组的最精确近似值。。。然而,“正常”使用关联数组的最佳比较是 Dictionary<string, object> 甚至可能 Dictionary<string, string>

    A. 哈希表 很适合那张地图。