dpvhv66448 2013-08-30 11:52
浏览 52

PHP SOAP国家铁路咨询

EDIT:

I was getting an unauthorized fault. Turns out that was because I was supplied with an incorrect token. I've got a working token now, so no longer get unauthorized. However I am still getting an error. Now it is saying 'SOAP-ERROR: Encoding: object hasn't 'numRows' property'

How can I make numRows and crs child nodes of GetDepartureBoardRequest??

Thanks


I'm trying to access Live departures from National Rail Enquiries...

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

I have an access token.

I'm having issues with generating the client xml and authenticating.

According to the (very limited) docs, my soap envelope should look like this...

<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>

Mine currently looks like this:

<?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>

And this is the PHP I'm using to generate it:

<?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:
" . $client->__getLastRequest() . "
";
?>

And finally, this is the SOAP Fault Object I get back:

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/
)

This is driving me crazy, I just can't seem to get my head around what's going on. I've read all the PHP SOAP docs, and googled it to breaking point.

Any ideas?

  • 写回答

1条回答 默认 最新

  • duanbiaojin8860 2013-08-30 13:22
    关注

    Yes! Thanks hakre for pointing out the incorrect token.

    Turns out the other issue was due to how I was setting the args and making my call to GetDepartureBoard.

    Instead of doing this:

        $args =  array(
                   new SoapParam('10','ns1:numRows'),
                   new SoapParam('WIL','ns1:crs')
            );
    
    
      $response = $client->__call('GetDepartureBoard',$args);
    

    I should have been doing this:

        $args =  array(
                  'numRows'=>'10',
                   'crs'=>'MAN'
            );
    
      $response = $client->GetDepartureBoard($args);
    

    Works a treat now :)

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)