I have a WCF web service. I am trying to do some registration whenever a request is received by injecting MessageInspector and entering the AfterReceiveRequest () event.
For some reason, when I submit a web service request using WCFTestClient.exe, everything works fine. The message is logged and the request is executed as usual.
But when I submit a request for a web service using SOAPUI as a client, making a copy of the request message causes the body to simply show <body>... stream ...</body> and cannot be loaded as an XML document later for verification .
I assume that the request from WCFTestClient.exe was received with a buffered message body, and the request from SOAPUI is accepted as a stream body? How is this possible?
Is there any way to write code that allows me to make a copy of any of these versions? I have yet to figure out how to safely copy the streaming version, since CreateBufferedCopy () obviously does not achieve this.
Or can I configure WCF to create a buffered message body and never stream?
Here is the code that I use to register and copy the request message:
object IDispatchMessageInspector.AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext) { try { MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue); request = buffer.CreateMessage(); Message copy = buffer.CreateMessage(); LogRequest(copy); ValidateMessage(ref request); } catch (Exception e) { throw new FaultException<>()... } return null; }
A copy of the request message cannot be loaded into the XML document in the ValidateMessage () method if it came from a SOAPUI with a streaming body. It is successfully loaded as an XML document if it comes from WCFTestClient.exe with a buffered body.
void validateMessage(ref System.ServiceModel.Channels.Message message) { XmlDocument bodyDoc = new XmlDocument();
Exception thrown by the Load () method:
System.InvalidOperationException {"The specified node cannot be inserted as a valid child of this node, because the specified node is the wrong type." }
in System.Xml.XmlDocument.AppendChildForLoad (XmlNode newChild, XmlDocument doc) in System.Xml.XmlLoader.LoadDocSequence (XmlDocument parentDoc) in System.Xml.XmlLoader.Load (XmlDocument doc, XmlReml readerWhoo. XmlDocument.Load (XmlReader reader) when ...