none
Removing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance AND xmlns:xsd="http://www.w3.org/2001/XMLSchema?

    Question

  • Hi Everyone,
                        I am facing an issue while testing WCF for a client WS consumer. The server is not expecting  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" in the soap body tag. Does Anyone know any way to remove those?

    I appreciate your help !

    Thanks!

    Federico
    Monday, January 21, 2008 1:14 PM

Answers

  • Once you have access to the Message object, you can do any XML-based manipulations you need to on it.  See this post for examples:

    http://weblogs.asp.net/paolopia/archive/2007/08/23/writing-a-wcf-message-inspector.aspx

     

    Regarding the overall problem of removing xsi/xsd references, I'm not sure that you want to necessarily do that at all.  The xsi references are there to account for polymorphic cases where we need to specify the xsi:type so that we can deserialize to the correct CLR type.  If the service that is receiving these messages can't handle polymorphism, then you similarly shouldn't be using it on the client side. 

     

    Hope this helps,

     

    -- Dave

    Wednesday, January 23, 2008 1:57 AM

All replies

  • Hi Federico,

     

    You can get access to the raw Message by implementing a custom IClientMessageInspector and overwriting BeforeSendRequest:

    http://msdn2.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageinspector.aspx

     

    I'm not sure if there is an easier way to strip the xsi/xsd references or not.  I'll dig into it a little bit and let you know.  In the meantime, let me know if that helps solve your problem.

     

    -- Dave

    Monday, January 21, 2008 10:28 PM
  • Thanks Dave,
                        I will give a try and let you know my results.

    Thanks again

    Federico
    Tuesday, January 22, 2008 9:03 AM
  • I was able to get the message i want in a String, now i am trying to figure out how to make the string a new message.
    • Proposed as answer by rsfurlan90 Wednesday, July 06, 2011 2:15 PM
    • Unproposed as answer by rsfurlan90 Wednesday, July 06, 2011 2:15 PM
    Tuesday, January 22, 2008 3:57 PM
  • Once you have access to the Message object, you can do any XML-based manipulations you need to on it.  See this post for examples:

    http://weblogs.asp.net/paolopia/archive/2007/08/23/writing-a-wcf-message-inspector.aspx

     

    Regarding the overall problem of removing xsi/xsd references, I'm not sure that you want to necessarily do that at all.  The xsi references are there to account for polymorphic cases where we need to specify the xsi:type so that we can deserialize to the correct CLR type.  If the service that is receiving these messages can't handle polymorphism, then you similarly shouldn't be using it on the client side. 

     

    Hope this helps,

     

    -- Dave

    Wednesday, January 23, 2008 1:57 AM
  • Yes, i was reading that page yesterday ! Thanks anyway!

    I have solved the issue implementing those interfaces. I just took the body into an XMLNode and i sent it in the message factory.

    Thanks so much for all your help !
    Wednesday, January 23, 2008 12:22 PM
  • I had a similar problem when I used the DataContractSerializer explictly. What I ended up doing was creating my own wrapper class that derives from XmlWriter.

    The constructor of this new class takes an existing XmlWriter to forward calls to.

    I then overloaded all the methods to forward the calls to the existing XmlWriter and I put in logic for the following methods:

    1  
    2  
    3         public override void WriteStartElement(string prefix_, string localName_, string ns_)  
    4         {  
    5             if ((ns_ != null) && ns_.StartsWith("http://schemas.datacontract.org"))  
    6             {  
    7                 ns_ = null;  
    8             }  
    9             _writer.WriteStartElement(prefix_, localName_, ns_);  
    10         }  
    11  
    12         public override void WriteStartAttribute(string prefix_, string localName_, string ns_)  
    13         {  
    14             if ((ns_ == null) || (ns_ == "http://www.w3.org/2001/XMLSchema-instance"))  
    15             {  
    16                 _ignoreEndAttrCall = true;  
    17                 return;  
    18             }  
    19             _writer.WriteStartAttribute(prefix_, localName_, ns_);  
    20         }  
    21  
    22         public override void WriteString(string text_)  
    23         {  
    24             if (_ignoreEndAttrCall)  
    25             {  
    26                 return;  
    27             }  
    28             _writer.WriteString(text_);  
    29         }  
    30  
    31         public override void WriteEndAttribute()  
    32         {  
    33             if (_ignoreEndAttrCall)  
    34             {  
    35                 _ignoreEndAttrCall = false;  
    36                 return;  
    37             }  
    38             _writer.WriteEndAttribute();  
    39         } 

    There's a private boolean field called ignoreEndAttrCall that I didn't define in the code snipped above.
    Thursday, October 16, 2008 2:11 PM
  • Thank you hasanib.

    Do you know a way to hook up the customXmlWriter to the serializer. I am using WCF so i do not have any control on the serialization process. I could see you are using DataContractSerializer explicitly so you can set your customXmlWriter while serializing. But, In my case I am not using DataContractSerializer explicitly as WCF will be taking care of it.

    Monday, September 17, 2012 5:31 PM