Php 如何在注册SOAPWeb服务时设置标头?
我正在使用Php 如何在注册SOAPWeb服务时设置标头?,php,soap,nusoap,soapserver,Php,Soap,Nusoap,Soapserver,我正在使用nusoaplib(在PHP中)为客户端创建SOAPweb服务 下面是我的代码: <?php require_once('include/nusoap/nusoap.php'); function testFunction($msg){ return $msg; } $server = new soap_server(); $namespace = "http://www.test-site.com";
nusoap
lib(在PHP
中)为客户端创建SOAP
web服务
下面是我的代码:
<?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);
?>
我想要的是将标题标记作为子元素设置为信封标记,因此它应该如下所示:
<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小时,但找不到任何解决方案
如果有人知道这一点,我将不胜感激。您解决了问题吗?欢迎来到StackOverflow。感谢您抽出时间提供答案。虽然这段代码可以解决这个问题,但如何以及为什么解决这个问题将真正有助于提高您的帖子质量,并可能导致更多的投票。请记住,你是在将来回答读者的问题,而不仅仅是现在提问的人。请在回答中添加解释,并说明适用的限制和假设。
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');
}
}
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');
}
}