【问题标题】:Call WCF service from ASP.NET core 3.1 API从 ASP.NET core 3.1 API 调用 WCF 服务
【发布时间】:2020-10-22 03:33:50
【问题描述】:

当我尝试从 ASP.Net Core 调用 WCF 服务时出现以下错误,仅当 wcf 服务和 API 都部署在 IIS 10 上时才会发生这种情况。

Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker 调用者,任务 lastTask,下一个状态,作用域范围,对象状态,布尔值 isCompleted) System.ServiceModel.CommunicationException: 无连接 可能是因为目标机器主动拒绝了它。 ---> System.Net.Http.HttpRequestException: 无法建立连接,因为目标机器主动拒绝。 ---> System.Net.Sockets.SocketException (10061): 由于目标机器主动拒绝,无法建立连接。在 System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancelToken)

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

如有任何想法,将不胜感激。

谢谢, 帕尼

【问题讨论】:

  • 这可能是因为指定端口上没有服务监听,或者防火墙可能阻止了你。
  • 向我们展示您的代码如何从 .net 核心调用 WCF。

标签: c# asp.net wcf asp.net-core asp.net-web-api


【解决方案1】:

这是我的错,当我们向 .net 搁浅库添加 WCF 服务引用时,它最终会添加“ConnectedService.json”,这个 JSON 将引用 WCF 端点,我就这样过去了。 但实际上 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 端点的关键

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-29
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 2020-07-09
    相关资源
    最近更新 更多