I was given a project to connect to a webservice, executes certain action. Ther ewebservice required authentication. I was provided with the WSDL url and the certificate copy. I was not able to successfully connect to it using soapClient, I get this message:
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://somesite.com/WebService.svc?WSDL' : failed to load external entity "https://somesite.com/WebService.svc?WSDL"
Any advice, why i got this message?
Here's my code:
$url = 'https://somesite.com/WebService.svc?WSDL';
$certFile = 'certificate/cert.crt';
$keyFile='certificate/cert.key';
$caFile='certificate/cert.csr';
$client = new SoapClient($url,
array(
'local_cert' => $certFile,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'soap_version' => SOAP_1_2,
'authentication'=> SOAP_AUTHENTICATION_DIGEST,
'ssl' => array(
'verifypeer' => false,
'verifyhost' => false,
'key' => $keyFile,
'cafile' => $caFile,
'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,
)
);
Do you have any idea what's missing that made this fail? I've tried connecting it thru curl, I can succesfully connect. My problem with CURL is that I don't know how to call the actions in the webservice like "logme","postMessages" and etc.
Here's my CURL code:
$username = 'webservice';
$password ='abcdef';
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<logme>
<user>'.$username.'</user>
<pass>'.$password.'</pass>
</logme>
</soap:Body>
</soap:Envelope>';
$conn = curl_init();
curl_setopt( $conn, CURLOPT_SSLCERT, $certFile);
curl_setopt( $conn, CURLOPT_URL, $url );
curl_setopt( $conn, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt( $conn, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $conn, CURLOPT_FOLLOWLOCATION,true );
curl_setopt( $conn, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt( $conn, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $conn, CURLOPT_SSLKEY, $keyFile);
curl_setopt( $conn, CURLOPT_CAINFO, $caFile);
curl_setopt( $conn, CURLOPT_SSLCERT, $certFile);
curl_setopt($conn, CURLOPT_POST, true );
curl_setopt($conn, CURLOPT_POSTFIELDS, $xml_post_string);
$client = curl_exec($conn);
if($client === false)
{
echo 'Curl error: ' . curl_error($conn);
}
else
{
echo 'Congrats, no error!';
}
curl_close($conn);
When executing the CURL code, I will got the message "Congrats, no error!". SO my problem is, after the successfull connection. I don't know how to call the action of the WSDL or send request to the service. Any advice?
I have an update regarding the curl, this is the error message that I got
"HTTP/1.1 415 Cannot process the message because the content type 'text/xml;charset="utf-8"' was not the expected type 'application/soap+xml; charset=utf-8'.
</div>