使用 Soap 客户端进行 Windows 身份验证的 Web 服务

发布于 2024-12-11 07:08:13 字数 534 浏览 0 评论 0原文

我需要从 ac# 表单应用程序访问网络服务。

Web 服务需要 Windows 身份验证。

我使用以下代码:

ServiceDeskSoapClient sd = new ServiceDeskSoapClient();
sd.ClientCredentials.UserName.UserName = @"mydomain\myusername";
sd.ClientCredentials.UserName.Password = "mypassword";
sd.MyMethod();

但出现以下错误:

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'.

如何正确设置凭据,以便它使用 Windows 身份验证,而不是匿名?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌若浮生 2024-12-18 07:08:13

如果有人仍然需要这个,我今天很高兴找到它。这确实很简单:

var server = new MySoapClient();
if (server.ClientCredentials != null)
{
    server.ClientCredentials.Windows.AllowNtlm = true;
    server.ClientCredentials.Windows.ClientCredential = new NetworkCredential("MyUsername", "MyPassword", "MyDomain");
}

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");
}
醉生梦死 2024-12-18 07:08:13

在 <绑定> 中添加以下内容:客户端 app.config 中的部分:(

<security mode="TransportCredentialOnly">
  <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
  <message clientCredentialType="UserName" algorithmSuite="Default" />
</security>

来自 http://morrisbahrami。 blogspot.com.au/2011/02/http-request-is-unauthorized-with.html

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文