我有一个WCF服务(A),它用下面的配置调用另一个WCF服务(B)。
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
我正在从.net核心(v2.2)服务调用服务B。我有以下设置:
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
basicHttpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Ntlm;
basicHttpBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
// doesn't have Default as the option. Only TripleDes
//basicHttpBinding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.TripleDes
basicHttpBinding.MaxReceivedMessageSize = int.MaxValue;
basicHttpBinding.ReceiveTimeout = new TimeSpan(250000000000);//Timespan in nanoseconds.
EndpointAddress endpointAddress = new EndpointAddress("http://");
customerServiceClient = new CustomerServiceClient(basicHttpBinding, endpointAddress);
NetworkCredential networkCredential = new NetworkCredential("user", "password", "domain");
customerServiceClient.ClientCredentials.Windows.ClientCredential = networkCredential;
customerServiceClient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
我得到了错误:身份验证失败了,因为连接无法重用。下面是异常的部分堆栈:
{"Message":"Authentication failed because the connection could not be reused.","Data":{},"InnerException":{"Message":"Authentication failed because the connection could not be reused.","Data":{},"InnerException":null,"StackTrace":" at System.Net.Http.HttpConnection.DrainResponseAsync(HttpResponseMessage response)\r\n at System.Net.Http.AuthenticationHelper.SendWithNtAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean isProxyAuth, HttpConnection connection, HttpConnectionPool connectionPool, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)\r\n at System.Net.Http.AuthenticationHelper.SendWithAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean preAuthenticate, Boolean isProxyAuth, Boolean doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken)\r\n at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n...
请告诉我如何解决这个问题。此外,这个API将被部署到PCF中。
谢谢,阿伦
发布于 2020-01-14 08:01:03
目前,NetCore
不支持消息安全模式。因此,下面的语句将无法工作。
basicHttpBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
但是NetCore2.2
使用TransportCredentialOnly
安全模式支持WCF服务。
下面是调用服务的一个示例。
ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
NetworkCredential nc = new NetworkCredential("administrator", "abcd1234!");
client.ClientCredentials.Windows.ClientCredential = nc;
var result = client.TestAsync().Result;
Console.WriteLine(result);
添加连接服务引用后,绑定设置和端点已经在Reference.cs文件中进行了配置。
我们只需要修改默认的服务端点地址。
然后在客户端配置Windows凭据.在我这边,很管用。请确保您的客户端项目基于AspNet Core2.2
,此外,请参考官方的Github存储库中的讨论。可能对你有用。
https://github.com/dotnet/wcf/issues/2923
如果有什么需要我帮忙的,请随时通知我。
https://stackoverflow.com/questions/59720002
复制相似问题