肥皂网服务无法正常工作(PHP)

时间:2013-07-25 17:04:35

标签: php web-services soap wsdl

我已经查看了堆栈溢出,只发现了几个相关的线程,但它们没有解决我的问题。此外,对于它的价值,这是一个名为Estes的LTL运营商,我正试图通过它来实现这一目标。

以下是我正在使用的代码:



    $url = "http://www.estes-express.com/rating/ratequote/services/RateQuoteService?wsdl";
    $username = 'un';
    $password = 'pw';

    $client = new SoapClient($url);

    //Prepare SoapHeader parameters 
    $cred = array( 
        'user'      => $username, 
        'password'  => $password
    );

    $headers = new SoapHeader('http://ws.estesexpress.com/ratequote', 'auth', $cred);
    $client->__setSoapHeaders($header);

    $params = array( 
        "requestID"         => "20131724",
        "account"           => "9252066",
        "originPoint"       => array('countryCode' => 'US', 'postalCode' => "43537"),
        "destinationPoint"  => array('countryCode' => 'US', 'postalCode' => "43460"),
        "payor"             => 'S',
        "terms"             => 'PPD',
        "stackable"         => 'N',
        "baseCommodities"   => array('commodity' => array('class' => "55", 'weight' => "500") )
    );

    $return = $client->getQuote(array("rateRequest"=>$params));

    return $return;

以下是我的回复: [客户端] SOAP-ERROR:编码:对象没有'requestID'属性

对此的任何帮助都会很棒!

PS。我已经尝试将它们放在没有结果的stdClass()对象中。此外,如果你想检查它们,它们的WSDL就在代码中。

编辑: 这是请求应该是什么样的转储:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rat="http://ws.estesexpress.com/ratequote" xmlns:rat1="http://ws.estesexpress.com/schema/2012/12/ratequote">
   <soapenv:Header>
      <rat:auth>
         <rat:user>xxxxx</rat:user>
         <rat:password>xxxxxx</rat:password>
      </rat:auth>
   </soapenv:Header>
   <soapenv:Body>
      <rat1:rateRequest>
         <rat1:requestID>20131724</rat1:requestID>
         <rat1:account>9252066</rat1:account>
         <rat1:originPoint>
            <rat1:countryCode>US</rat1:countryCode>
            <rat1:postalCode>43537</rat1:postalCode>
            <!--Optional:-->
            <rat1:city>Maumee</rat1:city>
            <!--Optional:-->
            <rat1:stateProvince>OH</rat1:stateProvince>
         </rat1:originPoint>
         <rat1:destinationPoint>
            <rat1:countryCode>US</rat1:countryCode>
            <rat1:postalCode>23237</rat1:postalCode>
            <rat1:stateProvince>VA</rat1:stateProvince>
         </rat1:destinationPoint>
         <rat1:payor>S</rat1:payor>
         <rat1:terms>PPD</rat1:terms>
         <rat1:stackable>N</rat1:stackable>
         <rat1:baseCommodities>
            <!--1 to 99 repetitions:-->
            <rat1:commodity>
               <rat1:class>50</rat1:class>
               <rat1:weight>100</rat1:weight>
            </rat1:commodity>
         </rat1:baseCommodities>
      </rat1:rateRequest>
   </soapenv:Body>
</soapenv:Envelope>

2 个答案:

答案 0 :(得分:2)

这也让我感到震惊:被调用的SoapClients所期望的参数 not 包含正文中最外层的XML标记,在本例中为rateRequest,因为这是根据WSDL中的描述自动生成。相反,您需要传递一个结构(数组或对象),其中包含外部标记中定义的每个参数。

所以在你的情况下,你只需要改变它:

$return = $client->getQuote(array("rateRequest"=>$params));

到此:

$return = $client->getQuote($params);

顺便提一下,您粘贴的代码也有一个拼写错误,您可以在其中定义$headers,然后引用$headerlive demo with both changes显示“用户身份验证失败”。错误(大概是因为你很聪明,不给我们你真正的登录细节!)

答案 1 :(得分:0)

如果有人仍然遇到这个问题,为了让这个工作,我必须将$ params更改为一个对象,否则我会收到一个错误,“对象属性不存在”

$params = new stdClass();
$params->requestID = "20131724";
$params->account = "123456";
$params->originPoint = array('countryCode' => 'US', 'postalCode' => "43537");
$params->destinationPoint = array('countryCode' => 'US', 'postalCode' => "43460");
$params->payor = "S";
$params->terms = "PPD";
$params->stackable = "N";
$params->baseCommodities = array('commodity' => array('class' => "55", 'weight' => "100") );

$return = $client->getQuote($params);