1

I am having trouble setting the body of a PHP SOAP call. I believe I am close just dont know how to get it in the correct format.

Here is what I have thus far in PHP

    $client = new SoapClient('http://url');
    $username='username';
    $password='password';

    $headers='
        '.$username.'
        '.$password.'
    ';

    $securityTags = new SoapVar($headers, XSD_ANYXML);

    $header=new SoapHeader("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security",$securityTags,true);

    $client->__setSoapHeaders(array($header));

    //HOW DO I SET THE BODY????
    $params = array('deal'=>'PT10M', 'StoreIds'=>64);
    return $client->__soapCall("PullDeals", array('searchCriteria'=>$params));

Below is what the request should look like

<soapenv:Envelope xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:deal="http://url.com" xmlns:ns="http://url" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken wsu:Id="UsernameToken-145" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:Username>YOUR_USERNAME</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">YOUR_PASSWORD</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">JQT6P7Zd3COZerXkREww2g==</wsse:Nonce>
            <wsu:Created>2013-11-19T22:18:54.122Z</wsu:Created>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <ns:PullDeals>
         <ns:searchCriteria>
            <deal:MaxElapsedSinceUpdate>PT10M</deal:MaxElapsedSinceUpdate>           
            <deal:StoreIds><arr:long>64</arr:long></deal:StoreIds>
         </ns:searchCriteria>
      </ns:PullDeals>
   </soapenv:Body>
</soapenv:Envelope>

1 Answer 1

1

To compare your request to the what the request should look like add 'trace' => true to your soap client.

$client = new SoapClient("my.wsdl", array('trace' => true));

and then use echo $client->__getLastRequest(); to spit out the XML.

I usually just view it on the page with chrome's Inspector to see it nicely indented.

You can reformat your call accordingly after you see how it is being formed.

Failing that you can hard code the XML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.