简体   繁体   English

从 ASP.NET 内核 3.1 API 调用 WCF 服务

[英]Call WCF service from ASP.NET core 3.1 API

I am getting below error when I am trying to call WCF service from ASP.Net Core, this is happening only when both wcf service and API deployed on IIS 10. I am getting below error when I am trying to call WCF service from ASP.Net Core, this is happening only when both wcf service and API deployed on IIS 10.

Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) System.ServiceModel.CommunicationException: No connection could be made because the target machine actively refused it. Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) System.ServiceModel.CommunicationException: No connection could be made because the target machine actively refused it . ---> System.Net.Http.HttpRequestException: No connection could be made because the target machine actively refused it. ---> System.Net.Http.HttpRequestException:由于目标机器主动拒绝,无法建立连接。 ---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it. ---> System.Net.Sockets.SocketException (10061): 由于目标机器主动拒绝,无法建立连接。 at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)System.Net.Http.ConnectHelper.ConnectAsync(字符串主机,Int32 端口,CancellationToken cancelToken)

I am able to connect same WCF service from ASP.NET MVC controller.我能够从 ASP.NET MVC controller 连接相同的 WCF 服务。 It fails only when we access from .net core.只有当我们从 .net 内核访问时它才会失败。

Any thoughts here, will be greatly appreciated.任何想法在这里,将不胜感激。

Thanks, Pani谢谢,帕尼

It was my bad, when we add an WCF service reference, to .net stranded library it will end up with adding " ConnectedService.json ", this JSON will have reference to WCF endpoint, i was going by that. It was my bad, when we add an WCF service reference, to .net stranded library it will end up with adding " ConnectedService.json ", this JSON will have reference to WCF endpoint, i was going by that. But actually reference.cs was not reading a URL from ConnectedService.json, it was hard coded in reference.cs .但实际上 reference.cs 并没有从 ConnectedService.json 读取 URL,它是在 reference.cs 中硬编码的

Solution is I had overwrite the URL while creating an instance of service client.解决方案是我在创建服务客户端实例时覆盖了 URL。

SomeServiceClient = new MyWebService.SomeServiceClient(); SomeServiceClient = new MyWebService.SomeServiceClient(); IConfigurationRoot configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build(); IConfigurationRoot 配置 = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build(); SomeServiceClient.Endpoint.Address = new EndpointAddress(configuration?.GetSection("WSSettings")?.GetSection("WSEndPoint")?.Value); SomeServiceClient.Endpoint.Address = new EndpointAddress(configuration?.GetSection("WSSettings")?.GetSection("WSEndPoint")?.Value);

Where WSSettings is section in appsettings.json and WSEndPoint is key in that contain WCF endpoint其中 WSSettings 是 appsettings.json 中的部分,而 WSEndPoint 是包含 WCF 端点的关键

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM