2

I am new to Soap Api and i don't know about SOAP request. I dont have any ideal about how to call api using php. Below is out api xlm parameter.

<xsd:user_id>admin@uss.com</xsd:user_id>
<xsd:password>uss</xsd:password>
<xsd:shipment>
    <xsd1:courier>L</xsd1:courier>
    <xsd1:delivery_address_line_1>123 MAIN ST</xsd1:delivery_address_line_1>
</xsd:shipment>

I just try to call this api by using below code

       $xml_post_string = '';
       $soapUrl = 'https://sandbox.loomis-express.com/axis2/services/USSBusinessService?wsdl';
       $headers = array(
                    "Content-type: text/xml;charset=\"utf-8\"",
                    "Accept: text/xml",
                    "Cache-Control: no-cache",
                    "Pragma: no-cache",
                    "SOAPAction: $soapUrl", 
                    "Content-length: ".strlen($xml_post_string),
                ); //SOAPAction: your op URL




        $url = $soapUrl;

        // PHP cURL  for https connection with auth
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        // converting
        $response = curl_exec($ch); 
        curl_close($ch);

Thanks in advance

ravi.ideal
  • 31
  • 3

1 Answers1

0

Calling a soap server with Curl is really hard way to do this and requires some experiences. First of all; You are posting an empty variable to given server.

$xml_post_string = '';

You must put expected xml to into this variable. I checked Wsdl service in your code. I suggest to you use SoapUI to check which kind of XML and header parameters expecting by Soap Server.

For example, There is getVersion method on this soap server. When i call this method with SoapUI it will give you example Request XML and Raw Response.

Request XML (You must post this with your Curl Request):

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ws="http://ws.business.uss.transforce.ca">
   <soap:Header/>
   <soap:Body>
      <ws:getVersion/>
   </soap:Body>
</soap:Envelope>

Expected header for this request (And you must add this headers to your Curl request):

Content-Type: application/soap+xml;charset=UTF-8;action="urn:getVersion"
Host: sandbox.loomis-express.com

And the response:

    <?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><ns:getVersionResponse xmlns:ns="http://ws.business.uss.transforce.ca"><ns:return xmlns:ax27="http://dto.uss.transforce.ca/xsd" xmlns:ax25="http://ws.business.uss.transforce.ca/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax25:GetVersionRs"><ax25:error xsi:nil="true" /><ax25:version>3.1.8</ax25:version></ns:return></ns:getVersionResponse></soapenv:Body></soapenv:Envelope>

I suggest you to use PHP's soap client. Here is a good thread about it: How to make a PHP SOAP call using the SoapClient class

Community
  • 1
  • 1
mertizci
  • 538
  • 3
  • 12