0

I am currently using a custom IHttpHandler class for parsing requests and sending back responses. Are there any advantages to using any of the global.asax methods as well?

chobo
  • 31,561
  • 38
  • 123
  • 191

2 Answers2

4

What exactly are you trying to do?

IHttpHandler is useful for when you want precise control over the HTTP request / response, however typically this is when you are developing a framework - most of the time the same thing can be achieved elsewhere.

IHttpHandler certainly isn't commonly used for web services, for that you should look into either using WCF, or using ASP.Net web services (if you are targeting the .Net 2.0 framework where WCF is not available). Using a dedicated web services toolset will make it much easier to expose your service in a consistent way (via SOAP, JSON etc...)

I'm not quite sure how global.asax comes into it - global.asax is, well... global. Anything that you do here will apply to the entire web application, so in particular any handling of requests that you do here will apply to all requests that reach your application. This isn't the place that you should be implementing web serivces.

Justin
  • 84,773
  • 49
  • 224
  • 367
  • 1
    I initially tried using WCF, but it was too much of a learning curve to make it work with POST'ed XML requests, so I used a handler. What I was getting at in my post was is there any performance advantage of using the global.asax (or httpmodules) for certain parts of a web service, like custom authentication and checking the request origin? Does it make any difference? – chobo May 12 '11 at 16:08
1

If you mean HttpApplication events vs IHttpHandler, they're not really comparable.

HttpApplication events are usually used from IHttpModules for cross-cutting concerns that apply (in principle) to all HTTP requests.

This question explains the differences between IHttpModule and IHttpHandler

Community
  • 1
  • 1
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • Pretty good article, but I still don't fully understand if there is any advantage to putting certain aspects of my web service in an httpmodule. I'm thinking in terms of performance. – chobo May 12 '11 at 16:05
  • @chobo: performance has nothing to do here. It's like asking whether it's faster to use a hammer or a screwdriver: they're different tools for different things. – Mauricio Scheffer May 12 '11 at 16:21