c# - How to use this WebService in MVC ASP.NET -
i want use webservice (*.asmx
) in mvc asp.net. created class:
public class servicerouter : iroutehandler { private readonly string _virtualpath; private readonly webservicehandlerfactory _handlerfactory = new webservicehandlerfactory(); public servicerouter(string virtualpath) { if (virtualpath == null) throw new argumentnullexception("virtualpath"); if (!virtualpath.startswith("~/")) throw new argumentexception("virtual path must start ~/", "virtualpath"); _virtualpath = virtualpath; } public ihttphandler gethttphandler(requestcontext requestcontext) { return _handlerfactory.gethandler(httpcontext.current, requestcontext.httpcontext.request.httpmethod, _virtualpath, requestcontext.httpcontext.server.mappath(_virtualpath)); } }
then, in routerconfig.cs
, added:
routes.add("routename", new route("service", new routevaluedictionary() {{ "controller", null }, { "action", null }}, new servicerouter("~/webservice1.asmx")));
i can access web service, error message when clicked method invoke any:
server error in '/' application.
the resource cannot found.
how fix this?
**
after studying, able use webservice in asp.net mvc.
** way. in routerconfig.cs in add:
routes.ignoreroute("{resource}.asmx/{*pathinfo}");
according scott hanselman, request default not handled asp.net mvc routing mechanism:
why doesn't asp.net mvc grab request? 2 reasons. first, there's option on routecollection called routeexistingfiles. it's set false default causes asp.net mvc automatically skip routing when file exists on disk. (source)
Comments
Post a Comment