Reputation: 4319
I need to access a webservice from a c# forms app.
The webservice needs Windows Authentication.
I use the following code:
ServiceDeskSoapClient sd = new ServiceDeskSoapClient();
sd.ClientCredentials.UserName.UserName = @"mydomain\myusername";
sd.ClientCredentials.UserName.Password = "mypassword";
sd.MyMethod();
But get the following error:
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'.
How do I correctly set the credentials so it uses windows auth, not anonymous?
Upvotes: 6
Views: 42032
Reputation: 842
Add the following inside the <binding> section in the client's app.config:
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
(from http://morrisbahrami.blogspot.com.au/2011/02/http-request-is-unauthorized-with.html)
Upvotes: 7
Reputation: 491
In case anyone still needs this, I had the pleasure of figuring it out today. It really was quite simple:
var server = new MySoapClient();
if (server.ClientCredentials != null)
{
server.ClientCredentials.Windows.AllowNtlm = true;
server.ClientCredentials.Windows.ClientCredential = new NetworkCredential("MyUsername", "MyPassword", "MyDomain");
}
Upvotes: 9