Re: PHP SoapClient cannot generate valid soap request

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

 



Hi Robert,

Thank you for taking the time to look into this. Unfortunately it is still
not working.
Regarding the prepaid parameter I tried both the boolean and the string
value of true. In the wsdl the type is boolean. I also like your sugestion
of extending the SoapClient class and I will definitely do that once I get
this working.

I tested with a soap debugging tool. The xml request generated by the tool
(I filled just the values) works perfectly, but I still cannot generate the
request using SoapClient.

Below you can find the php with all your suggestions. After the php script
you can find the var_dump content of both the request and the response.


New PHP Code
----------------------
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$soapClient = new SoapClient("
https://webservices.rrts.com/rating/ratequote.asmx?WSDL";, array('trace' =>
1));
$ns = 'https://webservices.rrts.com/ratequote/';
$headerBody = array(
        'UserName'          => "xxxxxx"
        , 'Password'       => "xxxxxx"
        , 'Site'       => "xxxxx"
);
$header = new SOAPHeader($ns, 'AuthenticationHeader', $headerBody);
$soapClient->__setSoapHeaders($header);

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

try {
    $results = $soapClient->RateQuote(array($args));
}
catch (SoapFault $fault) {
    var_dump("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring:
{$fault->faultstring})");
    var_dump($soapClient->__getLastRequest());
    var_dump($soapClient->__getLastResponse());
}

Request Generated by SoapClient (the body is still empty)
------------------------------------------------------------------------------------
<?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>xxxxx</ns1:UserName>
<ns1:Password>xxxxx</ns1:Password>
<ns1:Site>xxxxx</ns1:Site>
</ns1:AuthenticationHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:RateQuote/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Response
---------------
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:xsd="
http://www.w3.org/2001/XMLSchema";>
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Server Exception</faultstring>
<faultactor>RateQuote</faultactor>
<detail>
    <Error xmlns="https://webservices.rrts.com/ratequote/
"><ErrorNumber>99999</ErrorNumber>
    <ErrorMessage>Server Exception</ErrorMessage>
    <ErrorSource>RateQuote</ErrorSource>
    </Error>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>


On Sun, Apr 20, 2014 at 2:52 PM, Robert Williams <rewilliams@xxxxxxxxxx>wrote:

> On Apr 19, 2014, at 11:00, Adam Tong <adam.tongu@xxxxxxxxx> wrote:
>
> > Below you will find my PHP script and a valid request generated by a soap
> > software.
>
> It would be helpful if you could also show us the output from your
> var_dump() calls.
>
> > I cannot figure out what I am doing wrong in the php script. Maybe it is
> > the array of elements that is wrong. Please help.
>
> I think you may be missing a couple of wrapper arrays; try this:
>
> $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.00,
>       ),
>    ),
> );
>
> You might also need to put the value of Prepaid into quotes (i.e., make it
> the string “true” instead of a boolean), depending on what the service is
> expecting.
>
> If that doesn’t work, send us the var_dump() output, especially from the
> __getLastRequest() call, as it’s much easier to see where things are going
> wrong when you can see exactly what’s currently being passed and compare it
> against the known-correct XML from the SOAP utility.
>
> As a tip, calling the service methods directly, instead of via
> __soapCall(), may be easier to read:
>
> $results = $soapClient->RateQuote(...);
>
> Also, I will often create a new class that extends SoapClient, then use
> @method phpDocumentor tags to document the service methods I’ll be using.
> Doing this enables the IDE to support features like code completion, among
> other benefits.
>
>
> --
> Bob Williams
> SVP, Software Development
> Newtek Business Services, Inc.
> “The Small Business Authority”
> 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