使用PHP cURL调用SOAP Web服务(从SOAPUI移动)

时间:2013-06-18 17:05:12

标签: php web-services soap curl soapui

我不确定这是否适合它,但我希望你们中的一些人熟悉PHP cURL以及SOAPUI。

我已成功使用SOAPUI提交了一个Web服务请求,但是使用php没有运气。 PHP目前超时30秒(我也尝试将超时提升到3分钟)。 SOAPUI请求大约需要3秒钟才能完成。

如果你们中的任何一个人能够发现我出错的地方,我们将不胜感激!

由于


以下是我的SOAPUI属性 - 端点是https://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svcenter image description here SOAPUI请求:

<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>

我从SOAPUI中获取了RawRequest并将其用作PHP的XML有效负载($ post_string)。

这是我的PHP代码 - 我怀疑错误来自SOAPAction,我从SOAPUI的操作属性中检索到:

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

1 个答案:

答案 0 :(得分:3)

你可以试试这个。这是我在.php中使用cURL进行SOAP Web服务时使用的内容。

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

我有时间尝试连接它。在您的最后尝试,看看它是否与您的用户名和密码一起使用。