Jump to content

How can we consume the WCF SSL Service in PHP client ?


hemantwithu

Recommended Posts

Hello All,

 

I have developed a WCF service with htttps enabled.I have tested in .NET environment by creating a .NET windows client and consumed the service.I want to consume the same service php.I am new to php.I have written the below code

<?php
class WsseAuthHeader extends SoapHeader 
{
    private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
    function __construct($user, $pass, $ns = null) 
    {    
        if ($ns) 
        {        
            $this->wss_ns = $ns;    
        }    

        $auth = new stdClass();    

        $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);     
        $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);    
        $username_token = new stdClass();    
        $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);     
        $security_sv = new SoapVar(        
                                new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),        
                                SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);    

        parent::__construct($this->wss_ns, 'Security', $security_sv, true);
    }
}
$my_cert_file=".../wamp/mycert.pem";


$options = array('soap_version'    => SOAP_1_2, 
            	 'exceptions'      => TRUE, 
                 'trace'           => TRUE, 
                 'wdsl_local_copy' => TRUE,
				 'style'           => SOAP_DOCUMENT,
				 'use'			   => SOAP_AUTHENTICATION_DIGEST,
				 'encoding'		   => SOAP_ENCODED,
				 'cache_wsdl'      => WSDL_CACHE_NONE,
				 'local_cert' 	   => $my_cert_file);

$username = "TestUser";
$password = "second";

$wsse_header = new WsseAuthHeader($username, $password);    

$client = new SoapClient('https://192.168.0.120/TravelPlanService.svc?wsdl',$options); 
$client->__setSoapHeaders(array($wsse_header));

try
{
	$phpresponse=	$client->Authenticate();
   // print $phpresponse->GetResult->Version;       
   	echo (bool)$phpresponse->AuthenticateResult;
    echo "</b><BR/><BR/>";
}
catch(Exception $e) 
{ 
    echo "<h2>Exception Error!</h2></b>"; 
    echo $e->getMessage(); 
}
?>

I have created a self signed certificate through online. Please provide me the solution to consume the HTTPS service in PHP .

Edited by hemantwithu
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.