1

I have created an MVC project (Say DeploymentTool) and added another webAPI project to the solution (Say DeploymentToolAPI), and hence NameSpace is different for both. Now what I want is, to call any HTTPPOST/ HTTPGET method of DeploymentToolAPI from outside, say POSTMAN or web browser. Do we need to update WebApiConfig.cs for that? If not, how can I find the URL of DeploymentToolAPI. I am able to call any method of DeploymentTool but it's not working in case of DeploymentToolAPI.

Would appreciate any help/ suggestions.

2 Answers 2

2
  1. Right click on your WEB API project and go to Properties
  2. Go on Web tab and you will see project URL textbox
  3. This will tell you the base url for your web api project. (ie. http://localhost:8526)
  4. Then go to WebApiConfig.cs to check URL route pattern.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web.Http;
    
    namespace StandardWebApiTemplateProject
    {
        public static class WebApiConfig
        {
            public static void Register(HttpConfiguration config)
            {
                config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "api/{controller}/{id}",
                    defaults: new { id = RouteParameter.Optional }
                );
            }
        }
    }
    

If you have Route Template like -

routeTemplate: "api/{controller}/{id}" then your url will be like 
ie. http://localhost:8526/api/ControllerName/89

and if you include action name in route template then case will be like below

routeTemplate: "api/{controller}/{action}/{id}" then your url will be like 
ie. http://localhost:8526/api/ControllerName/ActionName/89
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Ankush. You explanation #2 gave me what I was looking for. Thanks a lot.
1

Firstly you need to Set Multiple Startup Projects to make both your API service and the MVC web application start up simultaneously:

In Visual Studio right click your solution -> Properties -> Select "Multiple startup projects:" -> set the Action of both projects to Start:

Set Multiple Startup Projects in Visual Studio

Once this is done follow the instructions posted by @Ankush Jain or just copy the WEB API url from the browser window, because when you run the project after setting multiple startup projects you will see that both your web api service and the MVC web application will be opened in the browser in two different tabs.

1 Comment

Yeah got that. Thanks Denis.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.