Get IHttpHandler in WCF service

  • Thread starter Thread starter Alphapage
  • Start date Start date
A

Alphapage

Hello,

I want to get the IHttpHandler from a svc service.
With old asmx webservices, I get it using
WebServiceHandlerFactory.GetHandler .

How can I get IHttpHandler in WCF running in serviceHostingEnvironment :
aspNetCompatibilityEnabled="true" ?

Thanks in advance for your help.
 
OK; *why* do you want the handler? What do you want to do?

Most things you can do by looking at the WCF pipeline ("inspectors",
etc). Yes, cmopatibility mode is an option, but I wouldn't use it
unless I had to - WCF doesn't always run over http or via ASP.NET...

Marc
 
I only want to get the Handler as I was doing in an old asmx webservice.

Yes... but why; what do you want to do with the handler? The point is
that there may be different (but more than adequate) ways of doing
this with WCF. Quite simply, WCF isn't actually part of the ASP.NET
pipeline, and handlers are an ASP.NET feature. If you happen to be
running in ASP.NET, you *might* be able to get the handler (not sure)
via compatibility mode, but I would still consider this a hacky
solution, and it adds unnecessary overhead (the ASP.NET shims) to the
WCF stack.

So if you can tell me what you actually want to do, I might be able to
suggest an appropriate WCF way to do this...

Marc
 
I want to process the following code in WCF:

using System;
using System.Web;
using System.Web.UI;
using System.Web.Services.Protocols;
using System.Web.SessionState;

public class AspCompatWebServiceHandler :
System.Web.UI.Page, IHttpAsyncHandler, IRequiresSessionState
{
protected override void OnInit(EventArgs e)
{
IHttpHandler handler =
new WebServiceHandlerFactory ().GetHandler(
this.Context,
this.Context.Request.HttpMethod,
this.Context.Request.FilePath,
this.Context.Request.PhysicalPath);
handler.ProcessRequest(this.Context);
this.Context.ApplicationInstance.CompleteRequest();
}

public IAsyncResult BeginProcessRequest(
HttpContext context, AsyncCallback cb, object extraData)
{
return this.AspCompatBeginProcessRequest(
context, cb, extraData);
}

public void EndProcessRequest(IAsyncResult result)
{
this.AspCompatEndProcessRequest(result);
}
}


In order for AspCompatWebServiceHandler to work its magic, it must be
registered as the HTTP handler for ASMX files. You can register it using this
web.config file:
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="*.asmx"
type="AspCompatWebServiceHandler, __code" />
</httpHandlers>
</system.web>
</configuration>

Thanks for your help Marc.
 
Back
Top