Reputation: 2269
I'm working with WCF and trying to return a list (or an array) of objects back to my client. It seems to be working fine for standard types, and I can return custom objects, but not lists of custom objects (even if there is only one item in the list).
I've read a fair amount on the topic but can't seem to get anywhere with it. It's compiling ok, but on the client side, when I get to my function, the client throws an exception
"An error occurred while receiving the HTTP response. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details."
I've tried a few ideas, currently my object looks like this:
[DataContract]
public class FilePacket : IDisposable
{
//[MessageHeader(MustUnderstand = true)]
[DataMember]
public string fileName;
//[MessageHeader(MustUnderstand = true)]
[DataMember]
public long fileSize;
//[MessageBodyMember(Order = 1)]
[DataMember]
public System.IO.Stream fileByteStream;
public void Dispose()
{
if (fileByteStream != null)
{
fileByteStream.Close();
fileByteStream = null;
}
}
}
Upvotes: 0
Views: 426
Reputation: 2269
I've now got this working (thanks for the help folks). There seems to be a variety of things that can go wrong and cause problems. Firstly, I changed from a Stream to a MemoryStream; and made sure it was being used as such throughout (I did notice while trying a few options that you can set the DataContract up to use a Stream, and actually be using a FileStream; this caused havoc, and took a few minutes to notice).
I changed from DataContract to MessageContract (ensuring to set the MemoryStream as [MessageBodyMember(Order = 1)]).
In the App Config, I set my transferMode to "Streamed" and ensured the maxBufferSize was set to a huge value.
Upvotes: 0
Reputation: 32758
First thing you have to do is check whether you are using transferMode
as Streamed
in binding.
<system.serviceModel>
…
<bindings>
<basicHttpBinding>
<binding name="ExampleBinding" transferMode="Streamed"/>
</basicHttpBinding>
</bindings>
…
<system.serviceModel>
Second thing you should use MessageContract
.
[MessageContract]
public class FilePacket
{
[MessageHeader]
public string fileName;
[MessageBodyMember]
public System.IO.Stream fileByteStream;
...
}
Other than the fileByteStream
the remaining properties you should decorate with MessageHeader
attribute.
The final thing is make sure you have set correct value for maxReceivedMessageSize
property to overcome the size limitations.
See these references
http://msdn.microsoft.com/en-us/library/ms733742.aspx
http://msdn.microsoft.com/en-us/library/ms789010.aspx
Upvotes: 1