0

编辑:

我遇到了未经授权的故障。原来那是因为我得到了一个不正确的令牌。我现在有一个工作令牌,所以不再未经授权。但是我仍然收到错误消息。现在它说'SOAP-ERROR:编码:对象没有'numRows'属性'

如何使 GetDepartureBoardRequest 的 numRows 和 crs 子节点?

谢谢


我正在尝试从 National Rail Enquiries 获取实时出发...

https://staging.livedepartureboards.co.uk/ldbws/

我有一个访问令牌。

我在生成客户端 xml 和进行身份验证时遇到问题。

根据(非常有限的)文档,我的肥皂信封应该是这样的......

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://thalesgroup.com/RTTI/2010-11-01/ldb/commontypes" xmlns:typ="http://thalesgroup.com/RTTI/[put your version here]/ldb/types">
   <soapenv:Header>
      <com:AccessToken>
         <com:TokenValue>XXXXXXXXXXXXXXXXXXXXXXXXXX</com:TokenValue>
      </com:AccessToken>
   </soapenv:Header>
   <soapenv:Body>
      <typ:GetDepartureBoardRequest>
         <typ:numRows>10</typ:numRows>
         <typ:crs>MAN</typ:crs>
      </typ:GetDepartureBoardRequest>
   </soapenv:Body>
</soapenv:Envelope>

我的目前看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://thalesgroup.com/RTTI/2012-01-13/ldb/types" xmlns:ns2="http://thalesgroup.com/RTTI/2010-11-01/ldb/commontypes">
    <SOAP-ENV:Header>
        <ns2:AccessToken>
            <ns2:TokenValue>XXXXXXXXXXXXXXXXX</ns2:TokenValue>
        </ns2:AccessToken>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <ns1:GetDepartureBoardRequest/>
        <ns1:crs>MAN</ns1:crs>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这是我用来生成它的 PHP:

<?php
$token = 'XXXXXXXXXXXXXXXXXXXXXXXXX';

$client = new SoapClient("https://staging.livedepartureboards.co.uk/ldbws/wsdl.aspx",
                   array('trace' => TRUE));

$headerParams = array('ns2:TokenValue'    => $token);

$soapStruct = new SoapVar($headerParams, SOAP_ENC_OBJECT);
$header = new SoapHeader('http://thalesgroup.com/RTTI/2010-11-01/ldb/commontypes', 'AccessToken', $soapStruct, false);
$client->__setSoapHeaders($header);

try {

    $args =  array(
               new SoapParam('10','ns1:numRows'),
               new SoapParam('WIL','ns1:crs')
        );


  $response = $client->__call('GetDepartureBoard',$args);

}
  catch(Exception $e){
      print_r($e);
      }
      echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
?>

最后,这是我返回的 SOAP 故障对象:

SoapFault Object
(
    [message:protected] => SOAP-ERROR: Encoding: object hasn't 'numRows' property
    [string:Exception:private] => 
    [code:protected] => 0
    [file:protected] => /var/www/vhosts/MYSITE.co.uk/httpdocs/live-departures/index.php
    [line:protected] => 22
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [function] => __call
                    [class] => SoapClient
                    [type] => ->
                    [args] => Array
                        (
                            [0] => GetDepartureBoard
                            [1] => Array
                                (
                                    [0] => Array
                                        (
                                            [0] => SoapParam Object
                                                (
                                                    [param_name] => ns1:numRows
                                                    [param_data] => 10
                                                )

                                            [1] => SoapParam Object
                                                (
                                                    [param_name] => ns1:crs
                                                    [param_data] => MAN
                                                )

                                        )

                                )

                        )

                )

            [1] => Array
                (
                    [file] => /var/www/vhosts/MYSITE.co.uk/httpdocs/live-departures/index.php
                    [line] => 22
                    [function] => GetDepartureBoard
                    [class] => SoapClient
                    [type] => ->
                    [args] => Array
                        (
                            [0] => Array
                                (
                                    [0] => SoapParam Object
                                        (
                                            [param_name] => ns1:numRows
                                            [param_data] => 10
                                        )

                                    [1] => SoapParam Object
                                        (
                                            [param_name] => ns1:crs
                                            [param_data] => MAN
                                        )

                                )

                        )

                )

        )

    [previous:Exception:private] => 
    [faultstring] => SOAP-ERROR: Encoding: object hasn't 'numRows' property
    [faultcode] => Client
    [faultcodens] => http://schemas.xmlsoap.org/soap/envelope/
)

这让我发疯,我似乎无法理解正在发生的事情。我已经阅读了所有 PHP SOAP 文档,并在谷歌上搜索到了临界点。

有任何想法吗?

4

1 回答 1

0

是的!感谢 hakre 指出错误的令牌。

结果发现另一个问题是由于我如何设置参数并调用 GetDepartureBoard。

而不是这样做:

    $args =  array(
               new SoapParam('10','ns1:numRows'),
               new SoapParam('WIL','ns1:crs')
        );


  $response = $client->__call('GetDepartureBoard',$args);

我应该这样做:

    $args =  array(
              'numRows'=>'10',
               'crs'=>'MAN'
        );

  $response = $client->GetDepartureBoard($args);

现在可以享受美食了:)

于 2013-08-30T13:22:40.090 回答