How to consume the WCF SSL Service in PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hemantwithu
Forum Newbie
Posts: 1
Joined: Thu Jan 30, 2014 4:22 am

How to consume the WCF SSL Service in PHP?

Post by hemantwithu »

Hi all,

I am new to PHP . We have a service which is developed in WCF SSL Service and using Message Level Security . I have to consume that service in php application.

Can you please let me know how can we write the code ? I have tried like as below

Code: Select all

<?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);
    }
}
$options = array('soap_version'    => SOAP_1_2, 
            	 'exceptions'      => true, 
                 'trace'           => 1, 
                 'wdsl_local_copy' => true);


$username = "TestUser1";
$password = "User";

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

$client = new SoapClient('https://welcome.cloudapp.net/ChatApplication.svc?wsdl',$options); 
$client->__setSoapHeaders(array($wsse_header));

try
{
$phpresponse=	$client->CheckUser();


    
   	echo (bool)$phpresponse->CheckUserResult;
    echo "</b><BR/><BR/>";
}
catch(Exception $e) 
{ 
    echo "<h2>Exception Error!</h2></b>"; 
    echo $e->getMessage(); 
}
	?>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How to consume the WCF SSL Service in PHP?

Post by Christopher »

And what is the problem with the code you posted?
(#10850)
Post Reply