繁体   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.

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:由于目标机器主动拒绝,无法建立连接。 ---> System.Net.Sockets.SocketException (10061): 由于目标机器主动拒绝,无法建立连接。 System.Net.Http.ConnectHelper.ConnectAsync(字符串主机,Int32 端口,CancellationToken cancelToken)

我能够从 ASP.NET MVC controller 连接相同的 WCF 服务。 只有当我们从 .net 内核访问时它才会失败。

任何想法在这里,将不胜感激。

谢谢,帕尼

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. 但实际上 reference.cs 并没有从 ConnectedService.json 读取 URL,它是在 reference.cs 中硬编码的

解决方案是我在创建服务客户端实例时覆盖了 URL。

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

其中 WSSettings 是 appsettings.json 中的部分,而 WSEndPoint 是包含 WCF 端点的关键

暂无
暂无

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

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