14

I am trying to learn webservices in .NET mvc4. I tried creating a new Internet application and adding a Web service (asmx) to the project.

By default, the VS adds a "HelloWorld" Webservice. When I try to run it in the browser, I do get the list of operations, service description(WSDL) and the details of the HellowWorld operation. However, when I try invoking the webservice, it gives the following error :

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

I might be missing some basic step/setting I guess. Could some body help please. Thanks.

Eduardo M
  • 1,007
  • 11
  • 17
saurabh
  • 1,730
  • 2
  • 15
  • 13
  • My first question is why did you pick an ASMX web service over WCF? – Dan Teesdale Jun 12 '13 at 03:49
  • I have not picked ASMX. i am just trying create a Webservice as given in some book. I would eventually be using a WebAPI. However I wanted to create and example which would have both a WebAPI as well as a ASMX for demo purpose. – saurabh Jun 12 '13 at 04:05

1 Answers1

36

I got the answer from one of my colleagues :) .

When we invoke the service, the MVC tries to resolve the path as specified in RegisterRoutes. Hence it tries to find a controller with that name and a method with the name same as that of the operation inside that controller. The resolution, ignore the paths with .asmx extension. You can do that by adding the following line in RouteConfig.cs :

routes.IgnoreRoute("{*x}", new { x = @".*\.asmx(/.*)?" }); 

and it worked. Thanks.

saurabh
  • 1,730
  • 2
  • 15
  • 13
  • Also uselful answer http://stackoverflow.com/questions/4675367/ignoreroute-with-webservice-exclude-asmx-urls-from-routing for – Geovani Martinez Oct 23 '16 at 19:13
  • I know this is old, but thank you for the post. I have been struggeling with this for 7-8 hours. My local webservices stopped working and I could not find out, what was wrong untill I found this post. For others with the same problem, the "routes.ignoreRoutes.." is to be added in the RouteConfig.cs. – Troels Oct 01 '17 at 15:21