Access Secured Web service in C#
I have to consume a secured (https) web service, which requires a domain user credentials. I have following code to access the service.
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;
}
Whenever I call web.QueryProxyStatistics();
method, I get MessageSecurityException
exceptions. (The HTTP request is u开发者_开发百科nauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'.) is there anything wrong with code?
Try to use the following code:
web.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
精彩评论