简体   繁体   中英

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 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?

WCF should not be treated as simply http - ie 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM