We are developing a WCF service for streaming large amounts of data, so we decided to use the WCF Streaming function in conjunction with protobuf-net .
Context:
In general, the idea is to serialize objects in the service, write them to the stream, and send them. At the other end, the caller will receive a Stream object and can read all the data.
Currently, the service method code looks something like this:
public Result TestMethod(Parameter parameter)
{
var responseObject = new BusinessResponse { Value = "some very large data"};
var stream = new MemoryStream();
serializer.Serialize(stream, responseObject);
stream.Position = 0;
return new Result {ResultBody = stream};
}
The BusinessResponse object is serialized into a MemoryStream and returned from the method. On the client side, the call code is as follows:
var parameter = new Parameter();
var methodResult = channel.TestMethod(parameter);
var result = serializer.Deserialize<BusinessResponse>(methodResult.ResultBody);
return result;
, serializer.Deserialize() , methodResult.ResultBody, WCF MemoryStream, TestMethod.
:
, , - MemoryStream .
, .
:
, Custom ( TestMethod()) , ( "BusinessResponse" ).
, WCF Read() , , protobuf-net, , .
, .
, - , , .
- , protobuf-net?