WCF 4 REST - 获取写作的基础响应流对象

问题描述:

背景:我目前使用Visual Studio 2010的在线模板WCF REST服务模板40(CS)和它的作品非常适合我主要是基于JSON的服务。我甚至得到它返回一个图像时工作到返回流。

Background: I am currently using the Visual Studio 2010 online template "WCF REST Service Template 40(CS)" and it works great for my primarily JSON based service. I've even got it working to return a stream when returning an image.

方案:我目前正在研究服务器推送和放大器;多重/ X - 混合替代技术,以取代我目前使用轮询图像的方法。

Scenario: I am currently looking into the server push & multipart/x-mixed-replace technology to replace the polling for images method I am currently using.

的问题:我现在面临的问题是,我无法找到一个方法来得到一个REST请求的基础响应流,我知道了模板试图通过提取该帮助离我而去,但为了贯彻落实好多重/ X - 混合替换机制,我需要直接写入此流并完全控制了我写的东西给客户端。

The Problem: The issue I am facing is that I am unable to find a way to get the underlying response stream for a REST request, I know the the template is trying to help by abstracting this away from me, but in order to implement the multipart/x-mixed-replace mechanism properly i will need to write directly to this stream and have full control of what i write to the client.

任何帮助将是非常美联社preciated。服务器推送技术似乎太酷了!

Any help would be much appreciated. The server push tech seems so cool!

我在响应返回的各种各样的事情,包括文档,S preadsheets等,它看起来是这样的:

I have returned all sorts of things in the response, including documents, spreadsheets etc. It looks something like this:

[ServiceContract]
public class MyService
{
    [OperationContract]
    [WebGet(UriTemplate="{id}")]
    public Stream GetDocuments(int id)
    {
       WebOperationContext.Current.OutgoingResponse.ContentType = GetContentType();
       Stream result = CreateTemporaryStream();
       /* Write your data in the correct format */
       return result; 
    }  
}

您可以pretty的多少返回任何你希望的格式。客户端显然必须能够从响应解析流并提取各个流

You can pretty much return any format you wish. The client obviously have to be able to parse the stream and extract the individual streams from the response.