2013-10-10 123 views
0

我要開發一個SOAP客戶端,以及供應商給我這個規格:SOAP客戶端通過HTTPS使用SSL證書兩側

  • 將通過IP使用HTTPS來transmited,並會被打包成XML適應XML方案的不同定義的文檔。
  • 通信是同步的,第三方應該等待響應。
  • 每個請求和響應都會被簽名。

我使用從PHP SoapClient類外,一切工作正常,除了當我嘗試使用我的私人密鑰來建立與服務器的通信:

Code: WSDL | Message: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://remoteserver/CustomerManagementService?wsdl' : failed to load external entity "https://remoteserver/CustomerManagementService?wsdl 

然後我試圖創建一個.PEM文件,它包含了我的私有密鑰串聯起來我的證書,我在讀過:how to send SOAP request with SSL certificate in PHP?

但它仍然會返回一個錯誤:

SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://remoteserver:80/CustomerManager/proxy/CustomerManagementService?WSDL%2FGWTCommonResources%2Fwsdl%2FGWTCommonMessages' : failed to load external entity "http://remoteserver:80/CustomerManager/proxy/CustomerManagementService?WSDL%2FGWTCommonResources%2Fwsdl%2FGWTCommonMessages 

我想知道是否有某種方法可以準確獲取PHP的soapClient類發送的原始數據。我必須在哪裏設置供應商的證書。

我已經嘗試使用「$ client - > __ getLastRequest()」,但我得到一個NULL。這是我的代碼:

$client = new anotherSoapClient($service, array(
    'local_cert' => $pem, 
    'style'   => SOAP_RPC, 
    'use'   => SOAP_ENCODED, 
    'soap_version' => SOAP_1_2, 
    'authentication'=> SOAP_AUTHENTICATION_DIGEST, 
    'ssl'   => array(
     'ciphers'=> "SHA1", 
     'verify_peer' => false, 
     'allow_self_signed' => true 
    ), 
    'https' => array(
     'curl_verify_ssl_peer' => false, 
     'curl_verify_ssl_host' => false 
    ), 
    'cache_wsdl' => WSDL_CACHE_NONE, 
    'cache_ttl'  => 86400, 
    'trace'   => true, 
    'exceptions' => true, 
)); 

// Test connection 
echo BR.'Functions: <pre>';var_dump($client->__getFunctions());echo '</pre>'; 

$XMLrequest = $client->prepareRequest($email); 
$response = $client->__anotherRequest('getCustomerInfo', $XMLrequest); 

echo "REQUEST:\n" . $client->__getLastRequest() . "\n"; 

順便說一句,我用我的本地機器上的PHP 5.4.9和服務器有PHP 5.3.10和anotherSoapClient是誰擴展PHP SoapClient的類的類:PHP soapClient send custom XML

回答

1

你可能需要指定以下SoalClient選項:

$defaultEndpoint = "https://remoteserver/CustomerManagementService"; 
$uri = "https://remoteserver"; 
$client = new anotherSoapClient($service, array(
    'local_cert' => $pem, 
    'location'  => $defaultEndpoint, 
    'uri'   => $uri, 
    'style'   => SOAP_RPC, 
    'use'   => SOAP_ENCODED, 
    'soap_version' => SOAP_1_2, 
    'authentication'=> SOAP_AUTHENTICATION_DIGEST, 
    'ssl'   => array(
     'ciphers'=> "SHA1", 
     'verify_peer' => false, 
     'allow_self_signed' => true 
    ), 
    'https' => array(
     'curl_verify_ssl_peer' => false, 
     'curl_verify_ssl_host' => false 
    ), 
    'cache_wsdl' => WSDL_CACHE_NONE, 
    'cache_ttl'  => 86400, 
    'trace'   => true, 
    'exceptions' => true, 
)); 
2

爲了調試建議您的SOAP請求必須擴展SoapClient類外。

class SoapClientDebug extends SoapClient 
    { 
     public function __doRequest($request, $location, $action, $version, $one_way = 0) 
     { 
      // Add code to inspect/dissect/debug/adjust the XML given in $request here 

      // Uncomment the following line, if you actually want to do the request 
      // return parent::__doRequest($request, $location, $action, $version, $one_way); 
     } 
    } 

而且下次使用它在你的要求:

$client = new SoapClientDebug("x.wsdl"); 
     $response = $client->__soapCall($function); 
     echo $client->__getLastRequest(); 

希望它可以幫助調試代碼!

相關問題