locked
"No connection could be made because the target machine actively refused it" when calling service in MVC app RRS feed

  • Question

  • User-2147270405 posted

    I've inherited a production MVC app with a WebUI project and a WebSvc project in the solution, but sadly haven't inherited any docs or access to former devs. I'm obviously missing a configuration step when starting to work with the project, as the Web Service calls fail when debugging.  

    I am using IIS Express and VS 2019 (16.9), and have created virtual folders for the WebUI and the WebSvc via the project properties dialogs. All other settings were left as-is from the Solution in TFS. The Web app itself starts OK, but the first call to the WebSvc fails with the error:

    SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:802
    

    on the following code, where the value for reqUri is "api/Config/GetConfig". :

    var response = GetClient().GetAsync(reqUri).Result;
    
    

    The WebSvc project does have a ConfigController class, which implements ApiController through an ApiControllerBase class, and that is where the GetConfig method is, so the reqUri looks fine to me.

    I have the value "http://localhost:802/" in the WebSvc project properties for "Project Url", which was exactly what the project had before I got started. the project also shows "IIS Express" for the Server in both the  WebUI and WebSvc projects, but as best I can tell, the last time this project was run in the IDE was VS 2015 & IIS Express 7 I guess.

    I'm obviously missing a setup step, but this is the first time I've inherited a project without any setup notes or automation, so I don't know what I've missed.  Any help is appreciated.

    Thursday, March 18, 2021 4:35 PM

Answers

  • User475983607 posted

    The error usually means you forgot to host (start) the service.  Right the service project and select "Set as Startup project".   Then press ctrl-F5 to start hosting the service in IIS Express.  Then right click the client project and select "Set as Startup project" and run the project. 

    You can also configure startup behavior in the solution properties; right click on the solution and select properties.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 18, 2021 8:14 PM

All replies

  • User475983607 posted

    The error usually means you forgot to host (start) the service.  Right the service project and select "Set as Startup project".   Then press ctrl-F5 to start hosting the service in IIS Express.  Then right click the client project and select "Set as Startup project" and run the project. 

    You can also configure startup behavior in the solution properties; right click on the solution and select properties.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 18, 2021 8:14 PM
  • User-2147270405 posted

    The error usually means you forgot to host (start) the service.  Right the service project and select "Set as Startup project".   Then press ctrl-F5 to start hosting the service in IIS Express.  Then right click the client project and select "Set as Startup project" and run the project. 

    You can also configure startup behavior in the solution properties; right click on the solution and select properties.

    Bingo!! Thanks for the help!!

    Figured it was dead simple, but was out of ideas. Didn't occur to me to check that, since I expected the Solution in TFS to already handle that sort of thing like startup.   I mean surely the solution ran before, right?

    Thursday, March 18, 2021 8:20 PM