从PHP发送Soap身份验证标头到ASP.NET Web服务

时间:2013-03-14 20:06:43

标签: php asp.net web-services

我正在尝试将带有身份验证凭据的soap标头从PHP发送到ASP.NET Web服务。

/// <summary>
/// Soap Header for the Secured Web Service.
/// </summary>
public class TestWebServiceHeader : System.Web.Services.Protocols.SoapHeader
{
    public string Username;
    public string Password;
    public string AuthenticatedToken;
}


/// <summary>
/// Summary description for TestService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class TestService : System.Web.Services.WebService
{
    public TestWebServiceHeader AuthHeader;
    public SoapUnknownHeader[] UnknownHeaders;

    [WebMethod]
    [System.Web.Services.Protocols.SoapHeader("AuthHeader")]
    [SoapHeader("UnknownHeaders")]
    public string HelloWorld()
    {
        foreach (SoapUnknownHeader header in UnknownHeaders)
        {
            if (header.Element.LocalName == "AuthHeader")
            {
                // FOUND HEADER
            }
        }

        if (AuthHeader == null)
        {
            // NULL AuthHeader
        }

        return "Hello World";
    }
}

这是PHP

<?php
$service = new SoapClient("http://localhost/Orientation/TestService.asmx?wsdl");
$HeaderSecurity = array("Username"=>"user", "Password"=>"pass123");
$header = new SoapHeader('http://tempuri.org/', 'AuthHeader', $HeaderSecurity, false);
$service->__setSoapHeaders(array($header));   
$service->HelloWorld(); // Example

//$service = new SoapClient("http://localhost/Orientation/TestService.asmx?wsdl");
//$auth = array('user'=>'user', 'password'=>'pass123'); 
//$authvar = new SoapVar($auth, SOAP_ENC_OBJECT); 
//$header = new SoapHeader('http://tempuri.org/', 'AuthHeader xmlns="http://tempuri.org/"',      $authvar, false); 
//$service->__setSoapHeaders(array($header)); 
//$service->HelloWorld();
?>

在Web服务中,PHP的AuthHeader始终为null。我可以在捕获SoapUnknownHeaders时找到标题,标题名称是ns1:AuthHeader。如何在不使用SoapUnknownHeaders的情况下获取标题。如果我有标题对象,如何从标题中提取信息?此外,我一直无法将注释掉的部分用于PHP。 SOAP_ENC_OBJECT使呼叫更安全吗?

0 个答案:

没有答案