Re: PHP SoapClient cannot generate valid soap request

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Adam,

When you call the service methods directly, you don’t need the array wrapper on the parameter since the SoapClient class will take care of it for you. Thus:

   $results = $soapClient->RateQuote(array($args));

should just be:

   $results = $soapClient->RateQuote($args);

Back on my dev machine this morning, I gave your code a shot, and with the above change, it works. The service complained about a missing ‘Pieces’ value, though. I looked at the WSDL, and Pieces is a required value. Looks like ShipDate is also required. Adding both, I get this code:

$args = array(
   'request' => array(
      'OriginZip'       => 18106,
      'DestinationZip'  => 91752,
      'ShipmentDetails' => array(
         'ShipmentDetail' => array(
            'ActualClass' => 50,
            'Weight'      => 1200,
         ),
      ),
      'OriginType'      => 'O',
      'PaymentType'     => 'P',
      'COD'             => array(
         'Prepaid'   => true,
         'CODAmount' => 1200,
      ),
      'Pieces'          => 1,
      'ShipDate'        => '2014-04-24T00:00:00-00:00',
   ),
);

which works, generating this XML:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:ns1="https://webservices.rrts.com/ratequote/";>
  <SOAP-ENV:Header>
    <ns1:AuthenticationHeader>
      <ns1:UserName>xxxxxx</ns1:UserName>
      <ns1:Password>xxxxxx</ns1:Password>
      <ns1:Site>xxxxx</ns1:Site>
    </ns1:AuthenticationHeader>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <ns1:RateQuote>
      <ns1:request>
        <ns1:OriginZip>18106</ns1:OriginZip>
        <ns1:DestinationZip>91752</ns1:DestinationZip>
        <ns1:ShipmentDetails>
          <ns1:ShipmentDetail>
            <ns1:ActualClass>50</ns1:ActualClass>
            <ns1:Weight>1200</ns1:Weight>
          </ns1:ShipmentDetail>
        </ns1:ShipmentDetails>
        <ns1:OriginType>O</ns1:OriginType>
        <ns1:PaymentType>P</ns1:PaymentType>
        <ns1:Pieces>1</ns1:Pieces>
        <ns1:COD>
          <ns1:Prepaid>true</ns1:Prepaid>
          <ns1:CODAmount>1200</ns1:CODAmount>
        </ns1:COD>
        <ns1:ShipDate>2014-04-24T00:00:00-00:00</ns1:ShipDate>
      </ns1:request>
    </ns1:RateQuote>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

As another tip, I noticed that you prepend your array elements with a comma. Presumably, this is to make adding new elements later less error-prone, which always a good idea. However, PHP offers an extremely useful feature that’s even better: dangling commas. Instead of this:

$foo = array(
   ‘apple’
   ,‘banana’
   ,‘pear’
   ,‘mango’
);

You can do this:

$foo = array(
   ‘apple’,
   ‘banana’,
   ‘pear’,
   ‘mango’,
);

Note the dangling comma after the last element. This idiom keeps code looking a bit more like natural language and also avoids future editing errors at the beginning of the array, which the comma-as-prefix arrangement doesn’t address. And if you ever find yourself generating array syntax programmatically, this feature makes doing so dead-simple.


--
Robert E. Williams, Jr.
Senior Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/


Notice: This communication, including attachments, may contain information that is confidential. It constitutes non-public information intended to be conveyed only to the designated recipient(s). If the reader or recipient of this communication is not the intended recipient, an employee or agent of the intended recipient who is responsible for delivering it to the intended recipient, or if you believe that you have received this communication in error, please notify the sender immediately by return e-mail and promptly delete this e-mail, including attachments without reading or saving them in any manner. The unauthorized use, dissemination, distribution, or reproduction of this e-mail, including attachments, is prohibited and may be unlawful. If you have received this email in error, please notify us immediately by e-mail or telephone and delete the e-mail and the attachments (if any).

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux