Reputation: 1326
I am calling a vendor web service and the schema of their calls requires custom namespaces in the body tag like this:
<s:Body xmlns:ddw="http://www.infinity.com/bpm/model/OmniLinkServices/DDWEBCallInput"
xmlns:omn="http://eclipse.org/stardust/models/generated/OmniLinkServices">
I could not find a good way via attribute configurations, binding configurations, etc to add this namespace, so I created an implementation of IClientMessageInspector to add the namespaces to the body tag. It works, but then the body of the message becomes:
<s:Body xmlns:ddw="http://www.infinity.com/bpm/model/OmniLinkServices/DDWEBCallInput"
xmlns:omn="http://eclipse.org/stardust/models/generated/OmniLinkServices">
... stream ...
</s:Body>
Note the odd ... stream ... contents of the body.
This is my implementation of BeforeSendRequest
on IClientMessageInspector
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
//Copy old message into XPathNavigator so as first step in transforming it to (newer) XDocument for modification
Message newMessage = null;
MessageBuffer msgbuf = request.CreateBufferedCopy(int.MaxValue);
XPathNavigator nav = msgbuf.CreateNavigator();
//load the old message into message stream via XmlWriter
MemoryStream ms = new MemoryStream();
XmlWriter xw = XmlWriter.Create(ms);
nav.WriteSubtree(xw);
xw.Flush();
xw.Close();
ms.Position = 0;
//load the XDocument from the XmlREader
XDocument xDoc = XDocument.Load(XmlReader.Create(ms));
ms.Close();
//add the sungard namespaces to the body of the message
var body = (from x in xDoc.Descendants() where x.Name.LocalName == "Body" select x).First();
var ddwns = new XAttribute(XNamespace.Xmlns + "ddw", "http://www.infinity.com/bpm/model/OmniLinkServices/DDWEBCallInput");
var omnns = new XAttribute(XNamespace.Xmlns + "omn", "http://eclipse.org/stardust/models/generated/OmniLinkServices");
body.Add(ddwns);
body.Add(omnns);
//create the new message
//write the XDoc back out to memory stream
MemoryStream newMsg = new MemoryStream();
xw = XmlWriter.Create(newMsg);
xDoc.Save(xw);
xw.Flush();
xw.Close();
newMsg.Position = 0;
//create the new message
XmlReader reader = XmlReader.Create(newMsg);
newMessage = Message.CreateMessage(reader, int.MaxValue, request.Version);
request = newMessage;
return null;
}
At the very end of the function, the XDocument
still has valid XML, but when I create the message at the end, that seems to be where the problem occurs.
Anybody have any thoughts?
Upvotes: 2
Views: 1007
Reputation: 1326
It appears that this is just the way WCF was logging the message. Looking at fiddler the entire xml is going through. I don't understand why WCF would log this way but whatever.
FYI for anybody else who runs into this.
Upvotes: 1