HTTP 404 error while invoking a local webservice in .NET MVC4

会有一股神秘感。 提交于 2020-01-01 08:24:32

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/17057386/http-404-error-while-invoking-a-local-webservice-in-net-mvc4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!