简体   繁体   中英

SOAP Client over HTTPS with SSL certificates on both sides

I have to develop a SOAP Client, and the supplier send me this specifications:

  • Will be transmited using HTTPS through IP, and will be Packaged as XML documents that adjust to the diferent defnitions of XML scheme.
  • The Communications is synchronous, the third party should wait for response.
  • Each request and response will be signed.

I'm using the soapClient class from PHP, and all works fine, except when I try to use my private key to establish communication with the server:

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

Then I tried creating a .pem file, it contains my private key concatenated with my certificate, as I've read in: how to send SOAP request with SSL certificate in PHP?

But it still returns an error:

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

I wonder if there is some way to get exactly the raw data that is being sent by the soapClient class of PHP. And where I must set the certificate of the supplier.

I've already tried with "$client->__getLastRequest()", but I'm getting a NULL. This is my code:

$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";

By the way, I'm using PHP 5.4.9 on my local machine and the server have PHP 5.3.10 and anotherSoapClient is a class who extend PHP soapClient class: PHP soapClient send custom XML

For debugging proposals your SOAP request you have to extend the SoapClient class.

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

And next use it in your request:

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

Hope it helps to debug your code!

You probably need to specify following SoalClient options:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM