Overriding the method RequestResponseAsync we are given the variable byte[] requestBody.
To deserialize this variable we use DataContractSerializer (or maybe NetDataContractSerializer) but either way we need to know what type it was before it was serialized.
public override Task<byte[]> RequestResponseAsync(IServiceRemotingRequestContext requestContext, ServiceRemotingMessageHeaders messageHeaders, byte[] requestBody)
{
using (var stream = new MemoryStream(requestBody)) {
DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(object));
object headers = dataContractSerializer.ReadObject(stream);
// LOG headers here!
// logger.log(headers.something);
}
return base.RequestResponseAsync(requestContext, messageHeaders, requestBody);
}
What Type we replace object with to get requestBody to deserialize properly? We want to deserialize it here specifically to log information from it and need to know the type requestBody was before the serialization in order to do that.