【问题标题】:Calling SOAP Web-Services with PHP cURL (moving from SOAPUI)使用 PHP cURL 调用 SOAP Web 服务(从 SOAPUI 迁移)
【发布时间】:2026-01-21 05:05:01
【问题描述】:

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

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

如果有人能指出我哪里出错了,将不胜感激!

谢谢


以下是我的 SOAPUI 属性 - 端点是 https://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svc: 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 代码 - 我怀疑错误来自我从 SOAPUI 的操作属性中检索到的 SOAPAction:

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

【问题讨论】:

  • 最好试试soapclient
  • 你能发布 WSDL 吗?
  • @Swapn14 我试过 Soapclient 但我也没有运气。他们不提供链接到的 wsdl,只有 .svc
  • @rawrzors 你在请求属性中使用用户名和密码吗?

标签: php web-services soap curl soapui


【解决方案1】:

你可以试试这个。这是我在 .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);

我确实超时尝试连接它。尝试一下,看看它是否适用于您的用户名和密码。

【讨论】:

  • 我尝试了添加安全标头的代码,但没有超时。但是,我没有得到回应(布尔(假))。至少这是进步!明天我会做更多的测试,让你更新。