Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法强制转换类型为';MessageBodyStream';输入';System.IO.MemoryStream';_C#_Wcf - Fatal编程技术网

C# 无法强制转换类型为';MessageBodyStream';输入';System.IO.MemoryStream';

C# 无法强制转换类型为';MessageBodyStream';输入';System.IO.MemoryStream';,c#,wcf,C#,Wcf,我正在以流的形式从wcf服务器返回一个memorystream。 当我在客户机中检索它并将其转换回MemoryStream时,我得到了这个错误 我不知道MessageBodyStream从哪里来,因为我从未使用过它。有人能告诉我这个问题的解决方案吗 谢谢。为什么不把它作为一个而不是内存流使用呢 你可能想读一篇博客文章,其中特别提到你看到的行为: 例如,如果您发送 MemoryStream,接收器将 将其作为 System.ServiceModel.Dispatcher.StreamFormatt

我正在以流的形式从wcf服务器返回一个memorystream。 当我在客户机中检索它并将其转换回MemoryStream时,我得到了这个错误

我不知道MessageBodyStream从哪里来,因为我从未使用过它。有人能告诉我这个问题的解决方案吗

谢谢。

为什么不把它作为一个而不是
内存流使用呢

你可能想读一篇博客文章,其中特别提到你看到的行为:

例如,如果您发送 MemoryStream,接收器将 将其作为 System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream 类(接收您发送的任何流) 如此)


以下是有关此主题的一些MSDN信息:

MessageBodyStream
MemoryStream
是不相关的类型,不能将一种类型强制转换为另一种类型。您可能只需要将返回的对象用作内存流。

建议,如果您想将此流作为内存流访问,则需要先将其读入内存流。因为。

错误是“无法将“MessageBodyStream”类型的对象强制转换为“System.IO.MemoryStream”类型。这是客户端上的错误。谢谢,我刚刚在谷歌上找到了相同的论坛帖子,并刷新了页面,以查看您的回复,链接相同:)@Josh,很高兴它有所帮助。但你为什么不接受这个答案呢?zespri在14分钟后用我已经发布的相同链接发布了答案。。。