2012-12-19 115 views
1

如何使用HTTPS webservice和.PEM客戶端證書創建PHP SOAP?使用HTTPS webservice和.PEM客戶端證書的PHP SOAP

當我這樣做,我收到了如下錯誤:

array(2) { [0]=> string(38) "testeResponse teste(teste $parameters)" [1]=> string(38) "testeResponse teste(teste $parameters)" }

Fatal error: Uncaught SoapFault exception: [wsse:InvalidSecurity] SOAP header missing in D:\Inetpub\wwwroot\SOAP\index.php:47 Stack trace: #0 [internal function]: SoapClient->__call('teste', Array) #1 D:\Inetpub\wwwroot\SOAP\index.php(47): SoapClient->teste(Array) #2 {main} thrown in D:\Inetpub\wwwroot\SOAP\index.php on line 47

代碼:

$client = new SoapClient($wsdl, array(
    'local_cert' => $localCert, 
    'passphrase' => $passphrase, 
    'style'  => SOAP_DOCUMENT, 
    'use'  => SOAP_LITERAL, 
    'exceptions' => true, 
    'trace'  => true) 
); 
$something = $client->teste(array()); 
echo $something->testeResult; 

回答

1

的警告並非是對PEM證書或SSL。它很簡單:

SOAP header missing

您找到SOAPHeader in the PHP manual。 PHP手冊中也有一些使用示例和用戶貢獻的註釋,也在本網站上。例如:

$auth = array(
    'UserName' => 'USERNAME', 
    'Password' => 'PASSWORD', 
    'SystemId' => array('_'=> 'DATA', 'Param' => 'PARAM'), 
); 
$header = new SoapHeader('NAMESPACE','Auth',$auth,false); 
$client->__setSoapHeaders($header); 

讓我知道你是否遇到問題。