Description
Hello
I'm looking for wcf replacement in the .netCore. REST is fine but is too slow when complex data types are being serialized.
It would be nice to have possibility to replace user data JSON serialization with custom one. It can be useful if Protobuf or another framework is used with improved serialization algorithms.
My initial idea was to serialize IpcRequest.Parameters
and IpcResponse.Data
as byte array and then call DefaultIpcMessageSerializer
However the problem is that not every type is serialized to binary so certain header has to be used to deserialize request\response data properly back to object.
For example, new interface like IIpcMessageDataSerializer
can be introduced.
It can be used by IpcReader
and IpcWriter
to serialize method parameter and|or result value.
Here is IpcWriter
class draft to explain it better
private readonly IIpcMessageDataSerializer _dataSerializer;
public IpcWriter(Stream stream, IIpcMessageSerializer serializer, bool leaveOpen, IIpcMessageDataSerializer dataSerializer)
{
_stream = stream;
_serializer = serializer;
_dataSerializer = dataSerializer;
_leaveOpen = leaveOpen;
}
public async Task WriteAsync(IpcRequest request,
CancellationToken cancellationToken = default(CancellationToken))
{
request.Parameters = request.Parameters.Select(_ => _dataSerializer.Serialize(_)).ToArray();
byte[] binary = _serializer.SerializeRequest(request);
await WriteMessageAsync(binary, cancellationToken);
}
public async Task WriteAsync(IpcResponse response,
CancellationToken cancellationToken = default(CancellationToken))
{
response.Data = _dataSerializer.Serialize(_);
byte[] binary = _serializer.SerializeResponse(response);
await WriteMessageAsync(binary, cancellationToken);
}
And adjust IpcReader
as below
public async Task<IpcRequest> ReadIpcRequestAsync(CancellationToken cancellationToken = default(
{
byte[] binary = await ReadMessageAsync(cancellationToken);
var req = _serializer.DeserializeRequest(binary);
req.Parameters = req.Parameters.Select(_ => _dataSerializer.Deserialize(_));
return res;
}
public async Task<IpcResponse> ReadIpcResponseAsync(CancellationToken cancellationToken = default(
{
byte[] binary = await ReadMessageAsync(cancellationToken);
var res = _serializer.DeserializeResponse(binary);
res.Data = _dataSerializer.Deserialize(res.Data);
return res;
}