【问题标题】:How do I send an array in SOAP?如何在 SOAP 中发送数组?
【发布时间】:2012-08-07 17:08:53
【问题描述】:

我有一个 PHP 文件,它发送 SOAP 请求

$client = new SoapClient('http://xyz');
$client->call('example', array('param1'=>'value2')

我想使用 SoapUI 执行相同的请求:

<soapenv:Envelope [..]>
   <soapenv:Header/>
   <soapenv:Body>
      <urn:call soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <param1 xsi:type="xsd:string">example</param1>
         <param2 xsi:type="xsd:anyType">
            ??
         </param2>
      </urn:call>
   </soapenv:Body>
</soapenv:Envelope>

如何在 XML 中编码上述示例?

【问题讨论】:

标签: php xml soap soapui soap-client


【解决方案1】:

应该是这样的:

<soapenv:Envelope [..]>
   <soapenv:Header/>
   <soapenv:Body>
      <urn:call soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <param1 xsi:type="xsd:string">example</param1>
         <param2 xsi:type="xsd:anyType">
            <param1 xsi:type="xsd:string">value2</param1>
         </param2>
      </urn:call>
   </soapenv:Body>
</soapenv:Envelope>

【讨论】:

    【解决方案2】:

    使用json_encode(),然后将数组作为字符串表示形式发送。

    【讨论】:

      【解决方案3】:

      在这种情况下,有一个不错的 PHP SOAP 客户端函数:$client-&gt;__getLastRequest()

      这表明,请求是这样构建的:

      <param2 xsi:type="ns2:Map">
          <item xsi:type="ns2:Map">
              <key xsi:type="xsd:string">param1</key>
              <value xsi:type="xsd:string">param2</value>
          </item>
      </param2>
      

      【讨论】:

        猜你喜欢
        • 2015-08-23
        • 2013-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多