I have written an ASP.NET composite control which includes some Javascript which communicates with a web service.
I have packaged the classes for the control and the service into a DLL to make it nice and easy for people to use it in other projects.
The problem I'm having is that as well as referencing the DLL in their project, the consumer of my control must also include a .ASMX file for the web service. Whilst it isn't a complicated file (just a one-liner which refers to the class in the DLL), I would like to avoid having it if I can.
Is there any way to avoid having to have the .ASMX file?
All suggestions gratefully received!
UPDATE: The article linked to in John Sheehan's response (below) does work - but not if you want to call the web service using AJAX. Does anybody know of an AJAX friendly version?
Try something like this. I don't know if it will work though. I got this idea from ELMAH, which creates a handler for a page that doesn't physically exist and then serves it up 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 though): http://www.codeproject.com/KB/aspnet/wsinaclasslibrary.aspx
I know this is very old question, but it hasn't been answered properly, so here it is:
Every *.ASMX request is by default handled by System.Web.Services.Protocols.WebServiceHandlerFactory
.
Looking into source code of this class in .NET reflector, it's possible to have webservice without ASMX file but you will need to call internal method CoreGetHandler
through reflection.
Following method will take your webservice and return its 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 your httphandler, it's just matter of calling
httpHandler.ProcessRequest(context)
Done. No ASMX and no web.config entries.
Here is a very good working article about your problem:
Creating Web Services in a Class Library project on Codeproject.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With