Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
742 views
in Technique[技术] by (71.8m points)

c# - Web Service with Windows Authentication with Soap Client

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 = @"mydomainmyusername";
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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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");
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...