Streaming serialized response chunks works well:
Your WCF binding configuration would resemble the following:
<binding name="myCustomBinding">
<binaryMessageEncoding />
<httpTransport transferMode="StreamedResponse"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" />
</binding>
Your Service method would look something like:
[OperationContract]
public Stream GetDataStream(string objectId)
{
Stream stream = new MemoryStream();
MyObject obj = Manager.GetObject(objectId);
DataContractSerializer serilizer = new DataContractSerializer(typeof(MyObject));
serilizer.WriteObject(stream, obj);
stream.Position = 0;
return stream;
}
And your client-side completed method would do something like:
static void client_GetDataStreamCompleted(object sender, GetDataStreamCompletedEventArgs e)
{
if (e.Error == null)
{
DataContractSerializer serializer = new DataContractSerializer(typeof(MyObject));
MyObject obj = serializer.ReadObject(new MemoryStream(e.Result)) as MyObject;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…