0

I have a GET-endpoint called GetPostalCodeXml but it doesn't seem to ever get routed correctly

The method is in a class called WebServiceController like so:

public class WebServiceController : ApiController
{
    [HttpGet]
    [ActionName("GetPostalCodeXml")]
    public HttpResponseMessage GetPostalCodeXml(string postalCode)
    {
        return Request.CreateResponse(HttpStatusCode.OK, "ok");
    }
}

In my WebApiConfig.cs file the following code is run:

        config.Routes.MapHttpRoute(
            name: "GetPostalCodeXml",
            routeTemplate: "WebService/GetPostalCodeXml",
            defaults: new { controller = "WebService", action = "GetPostalCodeXml" }
        );

I'm trying to make a GET-request to the endpoint with the following URL:
http://localhost:60736/WebService/GetPostalCodeXml?postalCode=73522
but it doesn't seem to ever work.

I have tried writing the route in different ways and changing the method name among other things. I have also tried reading on the Microsoft docs page on routing: https://learn.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api
I still do not understand what is wrong or what I can do to solve it. I feel like I am misunderstanding something basic. Please help

1 Answer 1

0

I feel pretty stupid now but the problem was me. I was making requests to the wrong port in my local IIS. Not that it matters to anyone else but the correct port was 60744 and not 60736. The routing was correct all along.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.