How to return stream from WCF service?

后端 未结 3 1369
梦如初夏
梦如初夏 2021-01-19 02:58

I\'m playing with protobuf-net and WCF. Here is code I created:

public class MobileServiceV2
{
    [WebGet(UriTemplate = \"/some-data\")]
    [Description(\"         


        
3条回答
  •  不思量自难忘°
    2021-01-19 03:18

    Just write to a MemoryStream, and rewind it. Do not Dispose() it in this case:

    var ms = new MemoryStream();
    Serializer.Serialize(ms, obj);
    ms.Position = 0;
    return ms;
    

    This does, however, mean that it buffers in memory. I could try and come up with some voodoo to avoid that, but it would be very complex.

提交回复
热议问题