如何在PHP的nusoap服务器中验证Soap Header?

时间:2014-05-13 11:16:38

标签: php soap nusoap

我正在尝试使用nusoap在php中创建.net soap服务的存根服务器。我无法在PHP代码中验证标头。 样品Xml是

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <AuthenticationHeader xmlns="http://tempuri.org/">
      <UserName>string</UserName>
      <Password>string</Password>
    </AuthenticationHeader>
  </soap:Header>
  <soap:Body>
    <getUserPackDetails xmlns="http://tempuri.org/" />
  </soap:Body>
</soap:Envelope>

我应该将soap标头解析为复杂类型还是有其他方法?

1 个答案:

答案 0 :(得分:0)

对于soap标头,我无法在nusoap中找到任何函数,但我们可以通过PHP获取接收内容来验证标头。

function doAuthenticate()
{
    $sSoapRequest = file_get_contents('php://input');
    if(isset($sSoapRequest))
    {
        $sUsername = hookTextBetweenTags($sSoapRequest, 'Username');
        $sPassword = hookTextBetweenTags($sSoapRequest, 'Password');
        if($sUsername=='testuser' && $sPassword=='test12345')
            return true;
        else
            return false;
    }
}
function hookTextBetweenTags($string, $tagname) {
    $pattern = "/<$tagname ?.*>(.*)<\/$tagname>/";
    preg_match($pattern, $string, $matches);
    return $matches[1];
}