Creating a web service without an .asmx file?

I wrote an ASP.NET composite control that includes some Javascript that interacts with a web service.

I packed the classes for the control and the service in a DLL to make it nice and easy for people to use it in other projects.

The problem I ran into is that just like the link to the DLL in their project, the consumer of my control must also contain the .ASMX file for the web service. Although this is not a complex file (just a single line that refers to a class in a DLL), I would like to avoid it if I can.

Is there a way to avoid having to have an .asmx file?

  • Can I register a service on a web server in Application_Start?
  • Is it possible to change the web.config link to it somehow?

All suggestions are gratefully received!

UPDATE:. The article related to John Sheikhan's answer (below) works, but not if you want to call a web service using AJAX. Does anyone know of a friendly version of AJAX?

+6
web-services
source share
5 answers

Try something like this. I don't know if this will work. I got this idea from ELMAH, which creates a handler for a page that does not physically exist, and then serves it from the assembly.

<configuration> <system.web> <httpHandlers> <add verb="*" path="*WebService.asmx" type="MyHandler.WebServiceHandler, MyHandler" /> </httpHandlers> </system.web> </configuration> 

EDIT: I was close, see this article (in VB): http://www.codeproject.com/KB/aspnet/wsinaclasslibrary.aspx

+5
source share

I know that this is a very old question, but did not answer it properly, so here it is:

Each * .ASMX request is by default processed by System.Web.Services.Protocols.WebServiceHandlerFactory .

Looking into the source code of this class in the .NET reflector, it is possible to have a webservice without an ASMX file, but you will need to call the internal CoreGetHandler method through reflection.

The following method will take your web service and return it to IHttpHandler.

 public IHttpHandler GetHttpHandlerForWebService(WebService webService, HttpContext context) { var webServiceType = webService.GetType(); var wshf = new System.Web.Services.Protocols.WebServiceHandlerFactory(); var coreGetHandler = wshf.GetType().GetMethod("CoreGetHandler"); var httpHandler = (IHttpHandler)coreGetHandler.Invoke(wshf, new object[] { webServiceType, context, context.Request, context.Response }); return httpHandler; } 

Once you have httphandler, you just need to call

httpHandler.ProcessRequest (context)

Done. There is no ASMX and no entries in web.config.

+3
source share

Here is a good article about your issue:

Create web services in a class library project in Codeproject.

+2
source share

Consider an example of page methods ( see this blog post ). All you have to do is add the web method attribute to the static method in aspx code. Then go to the PageMethod object from your client code (javascript). No ASMX files. Hope this helps.

0
source share

The short answer is no. ASMX is the entry point for any web service. There are alternatives if you use WCF, but this is not exactly the same thing.

-8
source share

All Articles