Soap Server with .net type Soap Header Authentication

Hi,

I was wondering if anyone knows how to include .net type soap headers (typically used for authentication) on the SERVER side of nusoap.

So assuming the following sample server code from an IBM redbook...

Code:
<?
require_once("./lib/nusoaplib/nusoap.php");
$ns="http://myurl";

$server = new soap_server();
$server->configureWSDL('ITSOcalcTax',$ns);
$server->wsdl->schemaTargetNamespace=$ns;

$server->register('taxcalc',
array ('amount' => 'xsd:string'),
array ('return' => 'xsd:string'),
$ns);

function taxcalc($amount) {
$calc=$amount * .08;
return new soapval('return','string',$calc);
}

$server->service($HTTP_RAW_POST_DATA);
?>


how do I include soap headers such as...


Code:
$header = (
"<UserCredentials xmlns='http://myurl/'>".
"<userId>".htmlspecialchars($user)."</userId>".
"<password>".htmlspecialchars($pass)."</password>".
"</UserCredentials>"
);


so that I can call the service with the following code...

Code:
<?
require_once("./lib/nusoaplib/nusoap.php");
$wsdl="http://myurl?wsdl";
$client=new soapclient($wsdl,'wsdl');
$user='Guest';
$pass='Test1234';
$param=array('amount'=>1000);

$header = (
"<UserCredentials xmlns='http://myurl/'>".
"<userId>".htmlspecialchars($user)."</userId>".
"<password>".htmlspecialchars($pass)."</password>".
"</UserCredentials>"
);
$results=$client->call('ITsocalcTax',$param,false,false,$header);
print_r($results);
?>


The "UserCredentials" class is pre-defined in the .net world and I need to conform to this.

Thank you.

-a




Hi,

I am posting the reply below that I got from Scott Nichol at sourceforge for the benefit of others asking the same question. I hope that's ok.

Please add more to this thread if you have any input.

Thank you.

-a


RE: nuSoap Server with .net type Soap Header (New)
By: Scott Nichol (snichol) - 2008-04-08 09:00
There are a couple of instance variables in the nusoap_server class that allow you to access SOAP Headers. Most generally, requestSOAP gives you the full SOAP request (the HTTP payload) as a string. You can then parse anything out of it that you want. The requestHeaders variable gives you just the SOAP headers in string form, with a caveat: namespace resolution is spotty or nonexistent. Finally, requestHeader gives you the headers parsed into associative arrays, similar to what you get as a return value from the call method of nusoap_client.

Your code might look like this (with no error checking):

Code:
function taxcalc($amount) {
global $server;

$userId = $server->requestHeader['UserCredentials']['userId'];
$password = $server->requestHeader['UserCredentials']['password'];

if (authenticate($userId, $password)) {
$calc=$amount * .08;
return new soapval('return','string',$calc);
} else {
return new nusoap_fault('SOAP-ENV:Client', '', 'Authentication failed');
}
}



RE: nuSoap Server with .net type Soap Header (New)
By: bit wit (bit_wit) - 2008-04-09 01:18
Hi Scott,

I am not sure yet what the issues will be about the namespace, but I will try what you suggested.

Thank you for answering me.

-a


Hi, thanks for details.

I tried to transfer SOAP header from .NET client to PHP web service as this method was described in this post. But instead login and password values on server side I have that $server->requestHeader is invalid expression in watch window. Sad Why? Thanks for any help!
PHP version is 5.2.5, Apache version is 2.2.

PHP web service is the same.
.NET client:

Code:
try
{
ITSOcalcTax service = new ITSOcalcTax();
service.Credentials = new NetworkCredential("a", "b");
service.Url = "http://localhost/PhpWebServices/myservice.php?XDEBUG_SESSION_START=3";

string tax = service.taxcalc("100");

Console.WriteLine("tax is " + tax);
}
catch (Exception exception)
{
Console.WriteLine("exception is " + exception.ToString());
}
Console.Read();


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值