【问题标题】:Why is PHP SoapClient / Webservice not giving a response?为什么 PHP SoapClient / Webservice 没有响应?
【发布时间】:2014-02-03 05:39:17
【问题描述】:

我有一个通过 SOAP 使用 Web 服务的脚本。我想知道为什么我没有收到来自服务器/端点 URL 的响应。对方说他们正在收到我的请求,所以这意味着脚本有效。唯一的问题是它没有给我回应。我还尝试获取最后一个请求、最后一个请求标头和最后一个响应,但没有任何反应。

你知道为什么会这样吗?

这是我的代码:

$wsdl = "http://imupost.co.za/momentum/CRMLeadService.wsdl";
$momurl = "https://integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0";
echo("Post to URL: {$momurl}\n");
$username = "817221";
$password = "1234";

echo("<pre>");
$client = new SoapClient ($wsdl, array('location' => $momurl, 'style' => SOAP_DOCUMENT, 'trace' => 1,  'soap_version' => SOAP_1_1, 'exceptions' => true, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'ssl_method' => SOAP_SSL_METHOD_TLS));

$header='
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:UsernameToken wsu:Id="UsernameToken-45">
            <wsse:Username>'.$username.'</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">'.$password.'</wsse:Password>
        </wsse:UsernameToken>
    </wsse:Security>
    ';

$headerSoapVar = new SoapVar($header,XSD_ANYXML); 
$soapheader = new SoapHeader('wsse', "Security" , $headerSoapVar , true);
$client->__setSoapHeaders($soapheader);

$params['createLead'] = array(
    'LeadSourceId' => '07d3d6fe-7682-e311-a16d-005056b81ea8',
    'AffiliateLeadReference' => '852800020',
    'Title' => array('Code' => '852800018'),
    'Initials' => 'MH',
    'PreferredName' => 'Jane',
    'FirstName' => 'Hudson',
    'LastName' => 'Craig',
    'PreferredCorrespondenceLanguage' => array('Code' => '852800001'),
    'PreferredCommunicationMethod' => array('Code' =>'852800000'),
    'HomePhoneNumber' => '0725222427',
    'BusinessPhoneNumber' => '0725584155',
    'MobilePhoneNumber' => '0723694259',
    'EmailAddress' => 'jhudson@gmail.com',
    'Notes' => 'IMU',
    'ProductCategories' => array('Code' => '9c7d3878-5295-e211-9330-005056b81ea8', 'Description' => 'Health - Personal')
); 

    $result = $client->__soapCall("createLead", array($params));
    echo "REQUEST:\n" . htmlentities($client->__getLastRequest())  . "\n";
    echo "RESPONSE:\n" . $client->__getLastResponse()  . "\n";
    print_r($client->__getLastRequestHeaders());

【问题讨论】:

  • 对不起,答案不正确。我删除了。您可以粘贴服务器正在接收的请求消息吗?我看到了你的 wsdl,里面有很多不同的命名空间。我不知道这段代码是否按照服务器的要求形成了您的请求。
  • 这也是个问题。正如您在我的代码中看到的那样,我尝试打印出请求,但没有显示任何内容。甚至无法显示请求标头。但是对方告诉我他们已经收到了请求。这有点奇怪。
  • @kingAm 好的,请求应该是这样的:hastebin.com/moxicisani.xml
  • 我已经通过使用soap ui soap request 比较了您的soap 请求。这是完美的。唯一的问题是收到您的回复。 echo $result 显示了什么?
  • 是的,我也一直在使用 SOAPUI 对其进行测试,并且运行良好。 echo $result 没有显示任何内容。

标签: php web-services soap wsdl soap-client


【解决方案1】:

我建议使用 try catch。

try {
  $client->__soapCall("createLead", array($params));
  echo $client->__getLastResponse();
} catch (Exception $e) {
  echo "<pre>Exception: ".print_r($e, true)."</pre>\n";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-16
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多