tags:

views:

814

answers:

2

Hi all, In my WCF service class which is in the same project as my WebSite I inherit from System.Web.UI.Page so that I have access to the Page.Response object but when I use it I get the error: "Response is not available in this context."

I want to save to a file the results passes in 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 can I do this if I can't access the Response object?

+1  A: 

WCF should not be treated as simply http - i.e. it won't normally make sense to do what you have suggested above. You can do something comparable by writing a "message inspector" that adds a WCF header. A WCF service is not a Page, and can't be treated as one.

For the request, there is as as ASP.NET compatibility flag that can be enabled (providing access to HttpContext.Current), but the general advice is: don't.

So: what is it you are actually trying to do? What is your objective here?

Marc Gravell
Hi Marc, any advice on my other comment below?
A: 

Thanks Marc.

Basically what I want to do is save the contents of a silverLight DataGrid to a csv file!

Silverlight does not support doing this so what i'm trying to do is take the contents of the grid (a List) and using WCF send that List back to my html page that hosts the silverlight. Now with my List and with access to the Response object I can save as a csv doc'.

So i'm at the point where I get the List out of my silverlight app using WCF but how then to get the List to my html page to that I can achieve this?

That won't work. You will need a regular http request to do this; ideally by getting silverlight to ask the host browser to make the request (via navigate etc).
Marc Gravell