0

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.

jmbmage
  • 2,487
  • 3
  • 27
  • 44
  • have you seen this related question?: http://stackoverflow.com/questions/34166193/how-to-add-message-header-to-the-request-when-using-default-client-of-azure-serv/34221661#34221661 – LoekD Sep 23 '16 at 12:34
  • @LoekD I updated the question, specifically we want to _deserialize_ `requestBody` and that other question didn't reveal anything about that part of it. – jmbmage Sep 23 '16 at 12:58
  • If you have control over who is calling you and the called service itself, you could add a header specifying the type @ the caller side and use that to deserialize @ server side. – LoekD Sep 23 '16 at 13:02

0 Answers0