如何在注册SOAP web服务时设置Header



我正在使用nusoap库(在PHP中(为客户端创建SOAPweb服务。

以下是我的代码:

<?php

require_once('include/nusoap/nusoap.php');
function testFunction($msg){
return $msg;
}
$server = new soap_server();
$namespace = "http://www.test-site.com";    
$server->configureWSDL("TEST_FUNCTION_SERVICE",$namespace);

$server->register("testFunction",      // Register Method
array('msg' => 'xsd:string'),    // Method Parameter
array('return' => 'xsd:string'), // Response
$namespace,                      // Namespace
false,                           // soapaction: (use default)
"rpc",                           // style: rpc or document
"encoded",                       // use: encoded or literal
"This is TEST Function"               // description: documentation for the method
);
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
@$server->service($POST_DATA);
?>

当我在浏览器中打开功能描述时(使用chrome中的Wizdler扩展(,它看起来如下:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<testFunction xmlns="http://www.test-site.com">
<msg>[string]</msg>
</testFunction>
</Body>
</Envelope>

我想要的是将Header标记设置为Envelope标签的子元素,因此它应该看起来像下面的内容:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Header>
<Authenticate_Info xmlns="http://www.test-site.com">
<UserName>[string?]</UserName>
<Password>[string?]</Password>
<EntityId>[int]</EntityId>
</Authenticate_Info>
</Header>
<Body>
<testFunction xmlns="http://www.test-site.com">
<msg>[string]</msg>
</testFunction>
</Body>
</Envelope>

我很难把它设置为9小时,但找不到任何解决方案。

如果有人知道这一点,我将不胜感激。

function testFunction($msg){
global $server;
$UserName = $server->requestHeader['Authenticate_Info']['UserName'];
$Password = $server->requestHeader['Authenticate_Info']['Password'];
$EntityId = $server->requestHeader['Authenticate_Info']['EntityId'];
if ($username=='xxxxx' and  $password=='xxxxx' and $EntityId=='xxxxx') {
return $msg;
}else{
return new nusoap_fault('SOAP-ENV:Client', '', 'Authentication failed');
}
}

最新更新