Accessing the Response object from my WCF service
In my WCF service class, which is in the same project as my WebSite, I inherit from System.Web.UI.Page so that I can access the Page.Response object, but when I use it I get the error : "The answer is not available in this context."
I want to save a file to be passed to my WCF service like so:
public void SendList(List<ListType> listTypes)
{
Response.Clear();
Response.ContentType = "text/plain";
Response.AddHeader("content-disposition", "attachment; filename=filew.csv");
//etc
}
How do I do this if I cannot access the Response object?
WCF shouldn't be thought of as just http - that is, it generally doesn't make sense to do what you suggested above. You can do something comparable by writing a "message inspector" which adds a WCF header. A WCF service is not Page
and cannot be considered as one.
For a request, there is both an ASP.NET compatibility flag that can be turned on (providing access to HttpContext.Current
), but the general advice is: do not.
So: what are you actually trying to do? What is your goal here?
source to share