Reputation: 588
I'm trying to send a SOAP - PHP request with a DER certificate (that means the certificate don't have a privateKey) but no success.
$local_cert = FULL_PATH_TO_MY_CERT;
$client = new SoapClient($wsdl, array(
'local_cert' => $local_cert,
'trace' => 1,
'exceptions' => 1,
'soap_version' => SOAP_1_1,
'encoding' => 'ISO-8859-1',
'compression' => (SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP),
'location' => 'https://webserviceurl:port/ws/servlet/ws'
));
Only I recieve this errors:
Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: Unable to set private key file `PATHTOMYLOCALCERT' [APP\Vendor\WebServices\MyWS.php, line 206]
Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: failed to create an SSL handle [APP\Vendor\WebServices\MyWS.php, line 206]
Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: Failed to enable crypto [APP\Vendor\WebServices\MyWS.php, line 206]
Warning (2): SoapClient::SoapClient(https://webserviceurl:port/ws/servlet/ws?wsdl) [soapclient.soapclient]: failed to open stream: operation failed [APP\Vendor\WebServices\MyWS.php, line 206]
Warning (2): SoapClient::SoapClient() [soapclient.soapclient]: I/O warning : failed to load external entity "https://webserviceurl:port/ws/servlet/ws?wsdl" [APP\Vendor\WebServices\MyWS.php, line 206]
but I've found a little trick (in php.net) using the function file_get_contents($local_cert); the errors are gone.
But a new error come from.
Result : string(773) "Error reading prefix:Action.Execute"
What I mean is... this error above... is comming from the WebService? because it cannot authenticate with my request?
Thanks everybody. (appreciate your answers)
Upvotes: 6
Views: 43554
Reputation: 8919
I'm using SSL certificate in my soap call.
In My case I'm giving absolute path on my server for wsdl
and for local_cert
I've already defined those in my class. Please note that I'm using my certificate in .pem
format.
public $local_cert = "/var/www/.../webroot/cert.pem";
public $wsdl = "/var/www/.../webroot/my_wsdl.wsdl";
$this->client = new SoapClient($this->wsdl, array(
"trace" => 1,
"exceptions" => true,
"local_cert" => $this->local_cert,
"uri" => "urn:xmethods-delayed-quotes",
"style" => SOAP_RPC,
"use" => SOAP_ENCODED,
"soap_version" => SOAP_1_2 ,
"location" => $this->location
)
);
In my certificate there are 2 parts. Certificate and RSA Private Key.
(1)-----BEGIN CERTIFICATE-----
MIIFjzCC....
....
-----END CERTIFICATE-----
(2)-----BEGIN RSA PRIVATE KEY-----
MIIEpAI....
....
ww==
-----END RSA PRIVATE KEY----
And most important you should use https
link for making a soap call. This is working fine for me.
Hope this will help you.
Upvotes: 7