SOAP不通过多维数组

时间:2010-10-26 08:45:13

标签: php soap

我有一个多维数组,例如:

$array = array(
    'a' => 1,
    'b' => 2,
    'c' => array('42'=>'foo', '43'=>'bar'),
    'd' => 4
)

我正在尝试将其提供给SOAP调用,如下所示:

$response = $client->SomeFunction($array);

生成的XML请求忽略'c'。为什么呢?

2 个答案:

答案 0 :(得分:0)

我已经找到了原因,但最初对我来说并不明显。

如果数组与服务器的期望不完全匹配,则不会将其放入XML中。

例如,从上面的示例中,如果服务器期待abd但不是c,那么c就是忽略并且不会在XML中显示。这种行为令人困惑。

答案 1 :(得分:0)

我也遇到了这个问题。它会给我和错误“服务不可用”。我做了你做的但仍然错误。

这是我的要求:

POST /webservice/User.asmx HTTP / 1.1 主持人:www.sample.com.au Content-Type:text / xml;字符集= utf-8的 内容长度:长度 SOAPAction:“http://www.sample.com.au/UpdateUserBatch

  

<UpdateUserBatch xmlns="http://www.sample.com.au/">
  <auth>
    <Username>string</Username>
    <Password>string</Password>
  </auth>
  <request>
    <CreateIfNotExist>boolean</CreateIfNotExist>
    <UpdateIfExists>boolean</UpdateIfExists>
    <UserProfile>
        <UserID>string</UserID>
        <BusinessID>string</BusinessID>
        <ExternalID>string</ExternalID>
        <Username>string</Username>
        <Password>string</Password>
        <Addresses xsi:nil="true" />
        <Demographics xsi:nil="true" />
        <Roles xsi:nil="true" />
      </UserProfile>
      <UserProfile>
        <UserID>string</UserID>
        <BusinessID>string</BusinessID>
        <ExternalID>string</ExternalID>
        <Username>string</Username>
        <Password>string</Password>
        <Addresses xsi:nil="true" />
        <Demographics xsi:nil="true" />
        <Roles xsi:nil="true" />
      </UserProfile>
    </Users>
  </request>
</UpdateUserBatch>

这是我传递参数的方式:

$param = array('username' => 'username', 'password' => 'password', 'request'=>array('CreateIfNotExist' => TRUE, 'UpdateIfExists' => FALSE), 'Users' => array('UserProfile'=> array('UserID' => 'usr123',
'BusinessID' => 'bus123',
'ExternalID' => 'ext123',
'Username' => 'test',
'Password' => 'testing'
)));