Remove xmlns attributes in WCF message XML

OvemiTiddible

New Member
I am trying to modify response/request of a (non .NET) Web server consumer WCF class with IClientMessageInspector interface. With the following code I can get the XML message and modify it:\[code\]void System.ServiceModel.Dispatcher.IClientMessageInspector.AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState) XmlDocument XMLDocument = new XmlDocument(); MemoryStream XMLMemoryStream = new MemoryStream(); XmlWriter XMLWriter = XmlWriter.Create(XMLMemoryStream); reply.WriteMessage(XMLWriter); XMLWriter.Flush(); XMLMemoryStream.Position = 0; XMLDocument.Load(XMLMemoryStream); // do the changes XMLMemoryStream.SetLength(0); XMLWriter = XmlWriter.Create(XMLMemoryStream); XMLDocument.WriteTo(XMLWriter); XMLWriter.Flush(); XMLMemoryStream.Position = 0; XmlReader XMLReader = XmlReader.Create(XMLMemoryStream); reply = Message.CreateMessage(XMLReader, int.MaxValue, reply.Version);}\[/code\]So I have an \[code\]XmlDocument\[/code\] object to modify. I accomplished adding prefixes, etc, but cannot remove namespace from a node. The XML structure is below:\[code\]<soapenv:Envelope xmlns:soapenv="http://env" xmlns:xsd="http://xsd" xmlns:xsi="http://xsi" xmlns:v1="http://v1"> <soapenv:Body> <v1:VM xmlns="http://v1"> <SH> <a>aa</a> <b>bb</b> </SH> </v1:VM> </soapenv:Body></soapenv:Envelope>\[/code\]I want to remove xmlns="http://v1" attribute from the v1:VM element. Actually I can delete the attributes programatically but it does not affect the final XML, I think xmlns attributes are handled specially.Is what I try to do possible with XmlDocument? If I have to create a new object from the scratch, how must I begin? Or XMLDocument is not suitable at all? Do you have another suggestion?
 
Back
Top