Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF中调用.net核心API的NTLM身份验证_C#_Wcf_.net Core - Fatal编程技术网

C# WCF中调用.net核心API的NTLM身份验证

C# WCF中调用.net核心API的NTLM身份验证,c#,wcf,.net-core,C#,Wcf,.net Core,我有一个WCF服务(a),它使用以下配置调用另一个WCF服务(B) <security mode="TransportCredentialOnly"> <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </

我有一个WCF服务(a),它使用以下配置调用另一个WCF服务(B)

<security mode="TransportCredentialOnly">
  <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
  <message clientCredentialType="UserName" algorithmSuite="Default" />
</security> 
我收到错误:身份验证失败,因为无法重新使用连接。下面是异常的部分堆栈:

{"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中

谢谢,
Arun目前,
NetCore
不支持消息安全模式。因此,下面的陈述不起作用

basicHttpBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
但是
NetCore2.2
仅支持带有
transportcredentially
安全模式的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存储库中的讨论。它可能对您有用。


如果有什么我可以帮忙的,请随时告诉我。

目前,
NetCore
不支持消息安全模式。因此,下面的陈述不起作用

basicHttpBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
但是
NetCore2.2
仅支持带有
transportcredentially
安全模式的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存储库中的讨论。它可能对您有用。


如果有什么我可以帮忙的,请随时告诉我。

非常感谢您在这里花费的时间和精力。但我仍然面临同样的问题——“身份验证失败,因为连接无法重用。”。现在了解详细信息:“目前,NetCore不支持消息安全模式”-这是否意味着如果服务要求消息安全,我们就不能从.net core连接?我根本没有得到一个构造函数为空的服务客户机。因此我求助于:customerServiceClient=new Trusted customerServiceClient(EndpointConfiguration.BasicHttpBinding_ITrustedCustomerService,“url”);是的,我也读过那个讨论。您能否使用基于Core2.2的控制台应用程序创建对服务的成功调用?您的NetCore(V2.2)服务是什么项目类型?我不明白你为什么没有构造函数。您是否使用Microsoft WCF Web Service Reference Provider并确保该项目基于Core2.2。我能够使该项目正常运行-@Abraham您之前放置的链接提到了“AppContext.SetSwitch”(“System.Net.Http.UseSocketsHttpHandler”,false);”。我把它放在代理的构造函数中,事情就开始了。非常感谢,先生。将标记您的帖子作为答案。非常感谢您在这里花费的时间和精力。但我仍然面临同样的问题——“身份验证失败,因为连接无法重用。”。现在了解详细信息:“目前,NetCore不支持消息安全模式”-这是否意味着如果服务要求消息安全,我们就不能从.net core连接?我根本没有得到一个构造函数为空的服务客户机。因此我求助于:customerServiceClient=new Trusted customerServiceClient(EndpointConfiguration.BasicHttpBinding_ITrustedCustomerService,“url”);是的,我也读过那个讨论。您能否使用基于Core2.2的控制台应用程序创建对服务的成功调用?您的NetCore(V2.2)服务是什么项目类型?我不明白你为什么没有构造函数。您是否使用Microsoft WCF Web Service Reference Provider并确保该项目基于Core2.2。我能够使该项目正常运行-@Abraham您之前放置的链接提到了“AppContext.SetSwitch”(“System.Net.Http.UseSocketsHttpHandler”,false);”。我把它放在代理的构造函数中,事情就开始了。非常感谢,先生。将您的帖子标记为答案。