Pani
Pani

Reputation: 155

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

Upvotes: 0

Views: 1468

Answers (1)

Pani
Pani

Reputation: 155

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

Upvotes: 1

Related Questions