Last post Aug 06, 2016 02:30 AM by Yohann Lu
Jul 28, 2016 01:34 AM|trogan|LINK
How do I debug a web api? I have my asp.net website in one copy of VS 2015 (community) and my client in another copy. Both access the same localhost. website. When I call a web api from my client it does not trigger a breakpoint in the website. The web api
itself works outside of vs.
Jul 28, 2016 02:32 AM|Yohann Lu|LINK
How do I debug a web api?
Firstly, you should run your Web API in VS.
If your the applications are hosted at different domains, you may should Enabling Cross-Origin Requests in ASP.NET Web API 2.
Then, we can call Web API from our client or some test tools.
In our Asp.net client, we can use the following code.
var baseUrl = Request.Url.GetLeftPart(UriPartial.Authority);
string fullPath = baseUrl + "/api/Values";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullPath);
request.Method = "Get";//post, put ...
request.KeepAlive = true;
request.ContentType = "appication/json";
//request.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string myResponse = "";
using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()))
myResponse = sr.ReadToEnd().ToString();
Some tools can help your test your Web API. You can refer the following link.
Testing Tools for web API:
Jul 28, 2016 03:08 AM|jmpalines|LINK
run your api using vs, it should show the default api page with the localhost:portnumber, append your controller name/ method name, this should hit your breakpoint.
If you want to use your client, point the uri to your running api with the portnumber as well, and then submit a post/get request to your method
Jul 28, 2016 11:32 AM|trogan|LINK
Thx but not happening.
Jul 28, 2016 11:34 AM|trogan|LINK
Thx. Am using same domains but breakpoints are not being hit.
Aug 06, 2016 02:30 AM|Yohann Lu|LINK
If you have already deployed Web API, then this cannot be debugged. In development mode (JS), we can be normal debugging.