【发布时间】:2017-11-17 09:59:12
【问题描述】:
我们有一个经过 Windows 身份验证的 WCF 服务。绑定配置如下。
<basicHttpBinding>
<binding textEncoding="utf-8" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
我正在尝试从测试应用程序调用服务,
try
{
BasicHttpBinding binding = new BasicHttpBinding();
binding.ReceiveTimeout = new TimeSpan(10, 10, 00);
binding.SendTimeout = new TimeSpan(10, 10, 00);
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
EndpointAddress endpoint = new EndpointAddress("ServiceUrl");
ChannelFactory<ICRMConnectorService> channelFactory = new ChannelFactory<ICRMConnectorService>(binding, endpoint);
channelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
var service = channelFactory.CreateChannel();
service.TestMethod();
}
catch (Exception ex)
{
throw ex;
}
调用返回错误,因为, 远程服务器返回错误:(401) Unauthorized.
有人可以帮忙吗?
【问题讨论】:
-
您没有提到该服务现在是否在本地,但也许这个问题可以提供帮助:stackoverflow.com/questions/11408318/…
-
不,服务不是本地的。它托管在同一域下的不同服务器上。
-
别介意,您是否有权测试服务或使用服务?还可以启用错误日志记录和 WCF 跟踪以检查是否通过 SOAP 传递了有效凭据。
-
身份验证是在明文(通过端口 389)还是在安全的 LDAP(端口 636)下完成的?我认为您需要对 636 进行身份验证。
-
问题当然不在于发布的客户端代码,因为它对我来说逐字逐句。尝试使用具有对服务器/服务的已知访问权限的特定用户名/密码凭据。
标签: c# wcf windows-authentication