NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
WebService with SSL Authentication


Joined: 14 Oct 2015
Posts: 1
Reply with quote
I've been trying to connect to a webservice that requires authentication. I've tried every suggestion that I get in the web but still not able to connect successfully. See my code below:

Code:

require_once('nusoap-0.9.5/lib/nusoap.php');
$url = 'https://sitename.com/Connect/WebServices/SentWebService.svc?WSDL';
$credentials=array(
                     'user'=>'WebTest',
                     'Password'=>'abcdef123'
                  );
$certFile = 'certificate.crt';
$keyFile='certificate.key';
$caFile='certificate.csr';

                  
$soapUI = new nusoap_soapUI($url, true);
//Read from a post to specify the soap version to prevent the application type error
$soapUI->soap_version = 'SOAP_1_1';
$soapUI->authtype = 'certificate';
$soapUI->soap_defencoding = 'UTF-8';
$soapUI->decode_utf8 = false;
$soapUI->username='TMSTestUser';
$soapUI->password='tmstest01';


$soapUI->certRequest['sslcertfile'] = $certFile;
$soapUI->certRequest['sslkeyfile'] = $keyFile;
$soapUI->certRequest['cainfofile'] = $caFile;
$soapUI->certRequest['verifypeer'] = 0;
$soapUI->certRequest['verifyhost'] = 0;


/*
//Tried to execute this but got the same error.
$soapUI->setUseCurl(true);   
$soapUI->setCurlOption( CURLOPT_RETURNTRANSFER, true );
$soapUI->setCurlOption( CURLOPT_FOLLOWLOCATION,true );
$soapUI->setCurlOption( CURLOPT_SSL_VERIFYHOST, false);
$soapUI->setCurlOption( CURLOPT_SSL_VERIFYPEER, false);
$soapUI->setCurlOption( CURLOPT_SSLKEY, $keyFile);
$soapUI->setCurlOption( CURLOPT_CAINFO, $caFile);
$soapUI->setCurlOption( CURLOPT_SSLCERT, $certFile);
$soapUI->setCurlOption( CURLOPT_ERRORBUFFER, 'curlError');
*/

$soapUI->call("setLogin, $credentials);

if ($soapUI->fault)
{
    print_r($result);

}
else
{
    // check result
    $err_msg = $soapUI->getError();
    if ($err_msg) {
        // print error msg
      //var_dump($soapUI->response);
      //  echo 'Error: '.$err_msg;
    }
   else
   {
        // print result
        echo 'Result: ';
        print_r($result);
    }

echo '<h2>Request</h2><pre>' . $soapUI->request, ENT_QUOTES . '</pre>';
echo '<h2>Response</h2><pre>' . $soapUI->response, ENT_QUOTES . '</pre>';
echo '<h2>Debug</h2><pre>' . $soapUI->debug_str, ENT_QUOTES . '</pre>';


See below for the Request and Result
Quote:
<h2>Request</h2>
<pre>
POST /Connect/WebServices/SentWebService.svc HTTP/1.0
Host: sitename.com
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://tempuri.org/ISentWebService/SetLogin"
Content-Length: 476

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns7913="http://tempuri.org"><SOAP-ENV:Body><SetLogin xmlns="http://tempuri.org/"><Set>WebTest</Set><Password>abcdef123</Password>
</SetLogin></SOAP-ENV:Body></SOAP-ENV:Envelope>3
</pre>


<h2>Response</h2>
<pre>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'.
Date: Wed, 14 Oct 2015 14:38:41 GMT
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Content-Length: 0
Connection: close
Content-Type: text/plain; charset=UTF-8

3
</pre>


Additional Information
Language Used: PHP
Version: PHP 5.5.9-1ubuntu4.11

php -i | grep -i soap
soap
Soap Client => enabled
Soap Server => enabled
soap.wsdl_cache => 1 => 1
soap.wsdl_cache_dir => /tmp => /tmp
soap.wsdl_cache_enabled => 1 => 1
soap.wsdl_cache_limit => 5 => 5
soap.wsdl_cache_ttl => 86400 => 86400
View user's profileFind all posts by lonelygirl86Send private message
WebService with SSL Authentication
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic