带有参数的SOAP客户端方法返回null,尽管有数据

时间:2015-04-27 13:22:52

标签: php xml soap

我调用的SOAP服务器有两个函数

  

GetUserInfo和   GetAllUserInfo

客户端完美地调用第二个函数并显示所有用户。但第一个函数返回null。我知道它与参数有关,所以我尝试了许多可能的方法,但仍然没有。这是肥皂的xml和我使用的功能。

1的 GetUserInfo

请求Xml:

<GetUserInfo>
 <ArgComKey xsi:type="xsd:integer”>ComKey</ArgComKey>
    <Arg>
      <PIN xsi:type="xsd:integer”>Job Number</PIN>
    </Arg>
</GetUserInfo>

响应Xml:

<GetUserInfoResponse>
  <Row>
   <PIN>XXXXX</PIN>
   <Name>XXXX</Name>
   <Password>XXX</Password>

2.GetAllUserInfo *

请求Xml:

<GetAllUserInfo>
   <ArgComKey xsi:type="xsd:integer”>ComKey</ArgComKey>
</GetAllUserInfo>

响应Xml:

<GetAllUserInfoResponse>
  <Row>
    <PIN>XXXXX</PIN>
    <Name>XXXX</Name>
    <Password>XXX</Password>
    < Group>X</ Group>

这是我为客户编写的代码,用于获取特定用户和所有用户。

try {
        $opts = array('location' => 'http://192.168.0.201/iWsService',
                       'uri'      => 'iWsService');
        $client = new \SOAPClient(null, $opts);
        $attendance = $client->__soapCall('GetUserInfo', array('PIN'=> 2));
        var_dump($attendance);
    } catch (SOAPFault $exception) {
        print $exception;
    }

当我使用空数组()参数调用GetAllUserInfo时,它返回所有用户。包括PIN = 2的用户。但GetUserInfo方法返回null。当我调用GetUserInfo方法时,我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

为了对GetUserInfo进行正确的SOAP调用,您需要知道2个参数:ComKeyPIN。在下面的SOAP调用中,我假设ComKey12345,但您必须将此值替换为有意义的值。请尝试使用以下代码:

try {
    $opts = array('location' => 'http://192.168.0.201/iWsService',
                  'uri'      => 'iWsService');
    $client = new \SOAPClient(null, $opts);
    $attendance = $client->__soapCall('GetUserInfo', array('ArgComKey'=>12345,
                                                           'Arg' => array('PIN' => 2)));
    var_dump($attendance);
} catch (SOAPFault $exception) {
    print $exception;
}

在这里,我尝试尽可能地匹配GetUserInfo请求的XML格式。

相关问题