Deserializing a FileStream on Client using WCF
Posted
by Grandpappy
on Stack Overflow
See other posts from Stack Overflow
or by Grandpappy
Published on 2010-04-05T16:24:52Z
Indexed on
2010/04/05
16:33 UTC
Read the original article
Hit count: 380
I'm very new to WCF, so I apologize in advance if I misstate something.
This is using .NET 4.0 RC1.
Using WCF, I am trying to deserialize a response from the server. The base response has a Stream as its only MessageBodyMember.
public abstract class StreamedResponse
{
[MessageBodyMember]
public Stream Stream { get; set; }
public StreamedResponse()
{
this.Stream = Stream.Null;
}
}
The derived versions of this class are actually what's serialized, but they don't have a MessageBodyMember attribute (they have other base types such as int, string, etc listed as MessageHeader values).
[MessageContract]
public class ChildResponse : StreamedResponse
{
[DataMember]
[MessageHeader]
public Guid ID { get; set; }
[DataMember]
[MessageHeader]
public string FileName { get; set; }
[DataMember]
[MessageHeader]
public long FileSize { get; set; }
public ChildResponse() : base()
{
}
}
The Stream is always a FileStream, in my specific case (but may not always be).
At first, WCF said FileStream was not a known type, so I added it to the list of known types and now it serializes. It also appears, at first glance, to deserialize it on the client's side (it's the FileStream type).
The problem is that it doesn't seem to be usable. All the CanRead, CanWrite, etc are false, and the Length, Position, etc properties throw exceptions when being used. Same with ReadByte().
What am I missing that would keep me from getting a valid FileStream?
© Stack Overflow or respective owner