'How does ILogger deserialize WCF Messages?
I have a IClientMessageInspector with a BeforeSendRequest and AfterReplyRequest. There are credentials in the body I want to strip out before logging (bad API design, I know, but not my API).
Anyways... I'm doing the whole CreateBufferedCopy/create two copy thing (one for logging, one to put back in the ref'd parameter). I'm doing so because once you do GetReaderAtBodyContents the Message is unusable. And all of this works.
But something is bugging me...
If I don't do any of the CreateBufferedcopy stuff, and just use ILogger to LogTrace the message as-is, it can do so but the message is still usable.
Anybody know how is it that ILogger is able to deserialize a Message's without leaving it unusable? Is ILogger somehow drilling down to the message's _operationFormatter?
Solution 1:[1]
Thanks to those who commented. I'm using .NET Core 6, although the having to implement a CreateBufferedCopy thing does not appear to be .NET Core specific (from what I've been able to read in the docs so far).
Using ILogger itself isn't a problem that I'm trying to be address. The same issue would happen if I were using Console.WriteLine.
From digging around in the debugger, it looks like getting to the Formatter is "firewalled" via Internal scoped functions and System.Private.ServiceModel.
I think the answer here is that Microsoft really, really doesn't want to let you look at a reply/response without copying it first (and then re-copying it before continuing).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jason |
