With all version of .Net until the 4.8, it was possible to easily catch all ingoing and outgoing traffic for SOAP services consumed with WCF for logging purpose, using IEndpointBehavior / IClientMessageInspector, as described here for example : https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.dispatcher.iclientmessageinspector.beforesendrequest?view=netframework-4.8
I would like to know how I can restore this, or achieve the same purpose as before in .Net 5.0. I need to trace all SOAP exchanges in a log file, previously I just have to do :
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
_logger.Debug("Reply received: " + Environment.NewLine + "{0}", reply.ToString());
}
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
{
_logger.Debug("Sending request: " + Environment.NewLine + "{0}", request.ToString());
return null;
}
To have it working, you need clientRuntime.MessageInspectors, and client.Endpoint.Behaviors to register the classes.
Despite I have registered nuget packages available for System.ServiceModel, and especially System.ServiceModel.Primitives.dll these properties seems to not exist anymore.