This project is read-only.

HttpResponseMessage is disposable?

Topics: Web Api
Feb 8, 2012 at 8:08 PM

I am just getting started with using Web API for creating some WCF service. After looking at quite a few examples, it seemed like the best way to properly set the Htpp status code, especially in the case of an exception, is to have the return value as a HttpResponseMessage. This is great, because I can easily set the status code, set the Locations header, etc. The only problem came in when I happened to run FxCop on the code and it started complaining that the HttpResponseMessage objects need to be disposed. It seems bad to return disposable objects from a web service. Can anyone give me more information on this, please? Is there a better way of doing what I want to do? Is this a problem?


Feb 9, 2012 at 2:06 AM

There is a way to turn off that warning, and you can set the reason to be that ownership is assumed by the invoker.

Feb 9, 2012 at 2:07 AM

I think its in the examples somewhere.

Feb 9, 2012 at 8:13 AM

Yes, I suppress that message.  The "Justification" is as digitalpacman says.