Matt T. McAlear
Matt T. McAlear

Reputation: 131

Soap web-service not working (PHP)

I have looked all over stack overflow and only found a couple threads related but they did not solve my problem. Also, for what it's worth, this is an LTL carrier by the name of Estes that I am trying to get this to work through.

Here's the code I'm using:



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

Here is the response I am getting: [Client] SOAP-ERROR: Encoding: object has no 'requestID' property

Any help on this would be great!

PS. I have already tried putting them in stdClass() objects with not result. Also, their WSDL is in the code if you want to check it out.

EDITED: Here is a dump of what the request should look like:

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

Upvotes: 2

Views: 1506

Answers (2)

Bullyen
Bullyen

Reputation: 808

In case anyone is still having trouble with this, in order to get this to work I had to change the $params into an object or else I would receive an error, "Object Property Does Not Exist"

$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);

Upvotes: 0

IMSoP
IMSoP

Reputation: 97638

This caught me out the other day, too: the parameters expected by the SoapClients called should not include the outermost XML tag within the body, in this case rateRequest, as this is generated automatically based on the description in the WSDL. Instead, you need to pass a structure (array or object) containing each of the parameters defined within that outer tag.

So in your case, you just need to change this:

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

to this:

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

Incidentally, your code as pasted also has a typo where you define $headers but then reference $header. A live demo with both changes shows instead a "User authentication failed." fault (presumably because you were wise enough not to give us your real login details!)

Upvotes: 2

Related Questions