简体   繁体   中英

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: No connection could be made because the target machine actively refused it. ---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it. at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)

I am able to connect same WCF service from ASP.NET MVC controller. It fails only when we access from .net core.

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. But actually reference.cs was not reading a URL from ConnectedService.json, it was hard coded in reference.cs .

Solution is I had overwrite the URL while creating an instance of service client.

SomeServiceClient = new MyWebService.SomeServiceClient(); IConfigurationRoot configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build(); 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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