为什么PHP SoapClient / Webservice没有给出响应?

时间:2014-02-03 05:39:18

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

我有一个通过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());

1 个答案:

答案 0 :(得分:1)

我建议使用try catch。

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