使用C#访问安全的Web服务

时间:2011-07-10 16:10:03

标签: c# web-services security

我必须使用安全(https)Web服务,该服务需要域用户凭据。我有以下代码来访问该服务。

    public string GetResponse()
    {
        var web = new ProxyStatisticsWebServiceSoapClient();
        web.ClientCredentials.Windows.AllowNtlm = true;
        web.ClientCredentials.Windows.ClientCredential = new NetworkCredential("username",
            "password", "domail");
        var result  = web.QueryProxyStatistics();

        return result;
    }

每当我调用web.QueryProxyStatistics();方法时,我都会遇到MessageSecurityException个例外情况。 (HTTP请求未经授权,客户端身份验证方案为“匿名”。从服务器收到的身份验证标头为“NTLM”。)代码有什么问题吗?

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码:

web.ClientCredentials.Windows.AllowedImpersonationLevel =  System.Security.Principal.TokenImpersonationLevel.Impersonation;
相关问题