使用Windows Authenticated WCF服务

时间:2012-03-01 17:45:26

标签: wcf wcf-security windows-authentication

我有一个Windows身份验证的WCF服务。

使用以下配置:

BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

binding.SendTimeout = TimeSpan.FromMinutes(60);
binding.CloseTimeout = TimeSpan.FromMinutes(60);
binding.OpenTimeout = TimeSpan.FromMinutes(60);
binding.ReceiveTimeout = TimeSpan.FromMinutes(60);

NexumCrmServiceClient client = new NexumCrmServiceClient(binding, new EndpointAddress("http://xxxxxx:81/xxxxxxxxxxxxxx.svc"));
client.ClientCredentials.Windows.AllowNtlm = true;
//client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
client.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("xxxxxxxx", "xxxxxxxx", "xxxxxxxxx");

我收到了这个错误:

  

没有终点收听   http://xxxxxx:81/xxxxxxxxxxxxxxxx.svc可以接受该消息。   这通常是由错误的地址或SOAP操作引起的。看到   InnerException(如果存在),以获取更多详细信息......

如果我使用以下配置:

BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;

binding.SendTimeout = TimeSpan.FromMinutes(60);
binding.CloseTimeout = TimeSpan.FromMinutes(60);
binding.OpenTimeout = TimeSpan.FromMinutes(60);
binding.ReceiveTimeout = TimeSpan.FromMinutes(60);

NexumCrmServiceClient client = new NexumCrmServiceClient(binding, new EndpointAddress("http://xxxxxx:81/xxxxxxxxxxxxxx.svc"));
client.ClientCredentials.Windows.AllowNtlm = true;
//client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
client.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("xxxxxxxx", "xxxxxxxx", "xxxxxxxxx");

我收到了另一个错误:

  

HTTP请求未经授权使用客户端身份验证方案   '匿名'。从服务器收到的身份验证标头是   '协商,NTLM'。

请您建议一个成功运行的配置吗?

提前致谢,

1 个答案:

答案 0 :(得分:5)

我相信你需要设置:

binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows

获取您的问题标题所指的内容。另外,请使用带有basicHttpBinding的Windows身份验证查看此MSDN article