rawrzors
rawrzors

Reputation: 167

Calling SOAP Web-Services with PHP cURL (moving from SOAPUI)

I am not sure if this is the right place for it, but I am hoping a few of you are familiar with PHP cURL as well as SOAPUI.

I have managed to successfully submit a web services request using SOAPUI, but have had no luck using php. PHP is currently timing out at 30 seconds (I also tried raising the timeout to 3mins). The SOAPUI request takes about 3 seconds to finish.

If any of you could spot where I went wrong, it would be greatly appreciated!

Thanks


Below are my properties for SOAPUI - endpoint is https://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svc: enter image description here SOAPUI Request:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:eclg:coursecopy:enterprisecourse" xmlns:v2="http://CCWS-Services.eCollege.com/EnterpriseServices/Types/v2.1/">

<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Action>urn:eclg:coursecopy:enterprisecourse:createcoursesection:request</wsa:Action>
<wsa:To>http://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svc</wsa:To>
</soap:Header>

<soap:Body>
     <urn:CreateCourseSection>
 <urn:createCourseSection>
***REMOVED****
 </urn:createCourseSection>
</urn:CreateCourseSection>
</soap:Body>

</soap:Envelope>

I took the RawRequest from SOAPUI and used it as the XML payload for PHP ($post_string).

Here is my PHP code -I suspect the error comes from the SOAPAction, which I retrieved from SOAPUI's Operation Properties:

define('XML_POST_URL', 'https://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svc');

         $headers = array(
        'Content-Type: text/xml; charset=utf-8',
        'Content-Length: '.strlen($post_string),
        'Accept: text/xml',
                'Cache-Control: no-cache',
                'Pragma: no-cache',
        'SOAPAction: urn:eclg:coursecopy:enterprisecourse:createcoursesection:request'
         );

    /**
     * Initialize handle and set options
     */

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 4000);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    /**
     * Execute the request and also time the transaction
     */

    $result = curl_exec($ch); 

Upvotes: 1

Views: 11733

Answers (1)

Halfwarr
Halfwarr

Reputation: 8103

You can try this. This is what I used when I wound up using cURL in .php for a SOAP Web-Service.

$envelope = '<soap:Envelope> .... </soap:Envelope>';

$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL,            "https://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svc" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT,        10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST,           true );            
curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $envelope); 
curl_setopt($soap_do, CURLOPT_VERBOSE, TRUE); 
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","SOAPAction: \"/soap/action/query\"", "Content-length: ".strlen($envelope))); 

$result = curl_exec($soap_do);

I do time out trying to connect to it. Try it on your end and see if it works with your username and password.

Upvotes: 3

Related Questions