I'm writing a small .NET Core app that needs to call a web service which uses MTOM encoding. I found the WcfCoreMtomEncoder (https://www.nuget.org/packages/WcfCoreMtomEncoder/0.1.16) and it's working fine to encode/decode the requests and responses.
However, I need to be able to log the requests and responses. I added an IEndpointBehavior class to the endpoint to do the logging, which works fine for the request. Unfortunately for the Response the IEndpointBehavior is getting called before the MTOM message is actually decoded so the response is logged as such:
<?xml version="1.0" encoding="utf-16"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header />
<soapenv:Body>... stream ...</soapenv:Body>
</soapenv:Envelope>
I've seen suggestions to add logging to an encoder instead, but the constructor for CustomBinding takes a BindingElement and I'm not sure where I would add the new encoder. Here's the code I have now:
var textMessageEncoding = new TextMessageEncodingBindingElement();
textMessageEncoding.MessageVersion = MessageVersion.Soap11;
var mtomBindingElement = new WcfCoreMtomEncoder.MtomMessageEncoderBindingElement(textMessageEncoding);
var httpTransport = new HttpTransportBindingElement();
httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Basic;
var binding = new CustomBinding(mtomBindingElement, httpTransport);
var endpoint = new EndpointAddress(config["EndpointURL"]);
fntClient = new FileNetServicesImplClient(binding, endpoint);
fntClient.Endpoint.EndpointBehaviors.Add(new MessageLoggingBehavior(log));
So how can I log the Response after it's decoded by the MTOM Encoder? Is there a way to move the EndpointBehavior so it happens after the decoding?