Last post Sep 24, 2015 12:23 PM by ido silverlight
Sep 22, 2015 05:13 AM|ido silverlight|LINK
Generic handlers has a property called IsReusable (boolean), which when set to true can decrease overhead by using the same handle instance by several different requests.
From what I have seen ASP.NET Web API does not offer a property like IsReusable, is that feature not supported anymore? does Web API already reusing the handler instance without me having to tell it to do so? if not, is there another way to tell Web API
to reuse handler instances?
Thanks a lot.
Sep 22, 2015 07:20 AM|Illeris|LINK
As far as I know, this feature does not exist in Web API, as it would not serve any purpose. What do you want to do? Why should it be reusable?
Sep 22, 2015 09:47 AM|ido silverlight|LINK
like I said, the IsReusable made it possible for asp.net to not create another instance of the handler's class type on subsequent requests to the same handler. Thus saving overhead.
That is a good thing (-:
Sep 22, 2015 11:06 AM|BinuRaghav|LINK
This may be helpful for you.
Sep 22, 2015 11:18 AM|Illeris|LINK
that is not a good thing. You try to convert something that is designed to be stateless to something that is statefull. It has not been made for that purpose. New call = new thread. Everything else is in the core architecture of ASP.NET MVC/WebAPI.
If you have specific issues or questions related to this, feel free to post them. I do not know any scenario's where this behavior imposes problems :-)
But you can always rewrite ASP.NET WebAPI :-). Actually if you want a controller to remain "active" for all calls, you could use the IOC functionality by overriding the IHttpControllerSelector and IHttpControllerActivator classes. See http://www.asp.net/web-api/overview/advanced/configuring-aspnet-web-api
Instead of creating a new controller instance for every request, you can cache the instance and use it for all requests. But beware: you can screw up easily. Do not do this unless you know what & why ;-)
Sep 22, 2015 01:29 PM|ido silverlight|LINK
By making a class stay in memory just so I don't have to create instance of it does not necessary say statefull:
if I don't store data outside of the ProcessRequest method (fields, properties) in the handler everything is stateless.
This feature just helps to reuse a class instance, that's all.
Sep 22, 2015 10:28 PM|Li Wang|LINK
According to the document of
Lifecycle of an ASP.NET Web API . A web api message is handled by
HttpMessageHandler instance. HttpMessageHandler doesn't implement IHttpHandler interface, it doesn't provide
Sep 23, 2015 04:33 AM|ido silverlight|LINK
Thanks Li Wang, that's the answer I was looking for.
With that in mind, Does that mean that a web service which was implemented by ASP.NET Web API has more overhead on the server side than a web service which was implemented by IHttpHandler? (assuming both has a lot of traffic with the same amount of requests
If you could clarify on my query above i'll appreciate it.
Sep 23, 2015 11:30 AM|ido silverlight|LINK
Here is a benchmark test, clearly Httphandler is faster than Web API:
Sep 23, 2015 09:12 PM|Li Wang|LINK
Httphandler is faster than Web API:
Yes, Pure httphandler is faster than web api. ASP.NET Web API is used for creating rich REST-ful Web Services that return JSON, XML, or any kind of content the web supports.
It can improve programming
efficiency. We must find a balance between
codes execution efficiency,
programming efficiency and code
Sep 24, 2015 12:23 PM|ido silverlight|LINK
I think you are right.