1

I am using IIS Express with a virtual directory for my MVC 3 project.

From the browser, the website works well - http://localhost:8080/VirtualDirectory/Home etc.

But I also have designed an API that I call from another desktop tool.

The problem is that it calls to http://localhost:8080/VirtualDirectory/Api/Action fails. It times out.

The same thing worked with Cassini web server without the VirtualDirectory from both browser and desktop tool.

Please help. What should I do? Any changes to web.config or MapRoute?

Niek de Klein
  • 8,524
  • 20
  • 72
  • 143
Gautam Jain
  • 6,789
  • 10
  • 48
  • 67

2 Answers2

1

If you are using web api, you should replace 'Action' for 'Controller':

http://localhost:8080/VirtualDirectory/Api/CONTROLLER
MuriloKunze
  • 15,195
  • 17
  • 54
  • 82
  • But "Api" is already a controller (ApiController). Will your solution still work? – Gautam Jain Dec 12 '12 at 15:32
  • You need a different route for web api like this: config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); – MuriloKunze Dec 12 '12 at 15:34
  • Note that a route for web api uses routes.MapHttpRoute() while a mvc route uses route.MapRoute() – MuriloKunze Dec 12 '12 at 15:35
  • I am using MVC3 where MapHttpRoute doesn't seem to be available. I am not in a position to upgrade to MVC4. – Gautam Jain Dec 13 '12 at 05:48
  • 1
    goths is not using Web Api, he just made a controller that is called Api. – Gabriel Dec 13 '12 at 06:32
0

You'll need to provide more details: Could you use Fiddler to see what's going on when issuing the POST to http://localhost:8080/VirtualDirectory/Api/Action with your desktop client?

Which version of IIS Express are you using?

If you made any changes to the default route could you paste them in the question?

Are the browser, IIS and the desktop client on the same machine?

Gabriel
  • 1,572
  • 1
  • 17
  • 26
  • Something strange is happening. I tried the url using Fiddler and there was no error. Then I tried my desktop client without changing anything & it started working. I closed Fiddler and then even my desktop client started failing. The request hangs for a long time and then goes to the right action with invalid POST data. But all works well when Fiddler is running side-by-side. – Gautam Jain Dec 13 '12 at 08:04
  • I think we found your issue then: http://stackoverflow.com/questions/1030218/httpwebreqest-works-with-fiddler-on-otherwise-timeout more info here: http://stackoverflow.com/questions/5827030/httpwebrequest-times-out-on-second-call – Gabriel Dec 13 '12 at 09:12
  • Yes, this most likely is the problem. But since I have written the client in VC++ MFC, I am finding it hard to achieve the same using the CHttpConnection & CHttpFile classes. I have been working on it since yesterday. Appreciate your perseverance to help me. – Gautam Jain Dec 14 '12 at 15:18
  • I think you should ask a new question in this case (your issue is not related to IIS / ASP.NET MVC). – Gabriel Dec 19 '12 at 07:50