如何使用SoapClient向函数传递参数?

3

很遗憾,我没有任何SOAP经验,请谅解我可能会在下面使用错误的符号 -

我收到了两个URL和一个XML字符串,我正在尝试从远程SOAP服务器获取XML响应。

第一个URL是WSDL文档,我将其提供给SoapClient构造函数:

$client = new SoapClient(URL_1, array('trace' => 1, 'exceptions' => 0));

第二个URL是SOAP服务器,我在这里使用它:

$client->__setLocation(URL_2);

这个很好用,我可以用以下代码检索 类型函数
print_r( $client->__getTypes() );
print_r( $client->__getFunctions() );

以下是输出的有趣部分:

[28] => struct GetServiceInfo {
 UserAuthentification UserAuthentification;
}

[74] => struct UserAuthentification {
 string UserId;
 string Password;
 string SessionKey;
}

[3] => GetServiceInfoResponse GetServiceInfo(GetServiceInfo $parameters)

我的问题是如何调用上述的GetServiceInfo函数。

我已经得到了这个XML字符串,可以在SoapUI程序中正常运行:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://...../V1">
  <soap:Header>.....</soap:Header>   
  <soap:Body>
      <v1:GetServiceInfo>
         <UserAuthentification>
            <UserId>MY_USERNAME</UserId>
            <Password>MY_PASSWORD</Password>
          </UserAuthentification>
      </v1:GetServiceInfo>
   </soap:Body>
</soap:Envelope>

请问如何在我的PHP脚本中传递这个参数?

我已经尝试过:

$result = $client->GetServiceInfo(array(
        new SoapParam( "UserAuthentification", array(   # ERROR, WANTS STRING HERE
        new SoapParam( "UserId", "MY_USERNAME" ),
        new SoapParam( "Password", "MY_PASSWORD" ),
)))); 

var_dump( $client->__getLastRequest() );
var_dump( $client->__getLastResponse() );

print_r( $result );

但是会收到以下错误提示:
Warning: SoapParam::SoapParam() expects parameter 2 to be string, array given in soap.php

Fatal error: SOAP-ERROR: Encoding: object has no 'UserAuthentification' property in soap.php

我觉得我在这里缺少一些细节,请帮忙。

更新:

我已经完成了以下步骤:

$user = array('UserId' => 'MY_USERNAME', 'Password' => 'MY_PASSWORD');
$params = array('UserAuthentification' => $user);
$result = $client->GetServiceInfo($params);

现在我遇到了错误:

[错误描述] => 无法识别服务

[错误原因] => wsa:To缺失,并且给定的URL /services无法映射到现有的服务


谢谢,我已经把你的建议转达给我的同事了,我自己没有太多时间来完成这个任务。 - Alexander Farber
1个回答

1

服务器使用WS-Addressing(如FaultReason所示-关键字是wsa:To),这在常规的PHP SoapClient扩展中不受支持。

我尚未使用WS-Addressing,但最近正在分析我们将来需要用到的项目的API。

请注意此项目其他项目可能会很有用(很容易搜索更多PHP WS-Addressing)。再次说明,我只是研究过相关内容,并没有任何实际编码经验来帮助您 :)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接