无法将"MessageBodyStream"类型的对象强制转换为"System.IO.MemoryStream"类型

Jos*_*osh 3 c# wcf

我从我的wcf服务器返回一个Stream形式的内存流.当我在客户端中检索它并将其转发回MemoryStream时,我收到此错误.

我不明白MessageBodyStream来自哪里,因为我从未使用过它.有人请告诉我这个问题的解决方案吗?

谢谢.

Luc*_*ero 7

为什么不用它Stream代替MemoryStream

您可能想阅读博文,其中特别提及您所看到的行为:

例如,如果发送MemoryStream,接收方将以System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream类的形式接收它(您发送的任何流都将作为此接收).

http://christopherdeweese.com/blog2/post/streaming-in-wcf-knowing-is-half-the-battle

以下是关于该主题的一些MSDN信息:http://msdn.microsoft.com/en-us/library/ms733742.aspx