XmlSerializer in SOAP message

Discussion in 'ASP .Net Web Services' started by Dima Maltsev, Dec 22, 2003.

  1. Dima Maltsev

    Dima Maltsev Guest

    Hi All,

    I would like to get rid of the following attributes when I
    serialize a class into an XML
    xmlns:xsd=http://www.w3.org/2001/XMLSchema
    xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance

    This is not a problem when you are in charge of creating
    an XmlSerializer object. All you need to do is to add an
    empty XmlSerializerNamespaces collection. Something like
    this:

    TestClass obj;
    XmlWriter writer;
    XmlSerializer xs = new XmlSerializer( typeof( TestClass ));
    XmlSerializerNamespaces namespaces =
    new XmlSerializerNamespaces();
    namespaces.Add( "", "" );
    xs.Serialize( writer, obj, namespaces );


    However, when you implement a Web Service method, you
    don't have access to XmlSerializer object.

    I am wondering how I can suppress the xmlns:xsd and
    xmlns:xsi xml namespaces serialization in this case?

    Thank you,
    Dima Maltsev
     
    Dima Maltsev, Dec 22, 2003
    #1
    1. Advertising

  2. Dima Maltsev

    MSFT Guest

    Hi Dima,

    To control the XML generated by an XML Web service, we can apply the
    attributes (Which control XML Serialization and Which control Encoded SOAP
    Serialization) to the classes, return values, parameters, and fields of a
    file used to create an XML Web service (.asmx). For specify a namespace,
    you may take a look at XmlRootAttribute Class:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
    frlrfSystemXmlSerializationXmlRootAttributeClassTopic.asp

    Hope this help,

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    MSFT, Dec 23, 2003
    #2
    1. Advertising

  3. Dima Maltsev

    Dima Maltsev Guest

    Hi Luke,

    Thank you for the reply.
    I am aware of XML Serialization attributes and I tried to
    use almost all of them. In particular, with
    XmlRootAttribute you can control the value for your own
    namespace (e.g. xmlns=www.dimamaltsev.com). However, no
    matter what you do with attributes it seems you cannot get
    rid of the following default namespaces:

    xmlns:xsd=http://www.w3.org/2001/XMLSchema
    xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance

    As I mentioned the only way I know how to remove them is
    to construct the XmlSerializer object and "tell" it not to
    use namespaces. Unfortunately, in case of Web Service
    implementation you do not create XmlSerializer (.NET
    framework does).

    Back to my question:
    Is there any away to get rid of
    xmlns:xsd=http://www.w3.org/2001/XMLSchema
    xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
    attributes in Web Service response?

    Happy Holidays to Everyone!
    Dima Maltsev
    >-----Original Message-----
    >Hi Dima,
    >
    >To control the XML generated by an XML Web service, we

    can apply the
    >attributes (Which control XML Serialization and Which

    control Encoded SOAP
    >Serialization) to the classes, return values, parameters,

    and fields of a
    >file used to create an XML Web service (.asmx). For

    specify a namespace,
    >you may take a look at XmlRootAttribute Class:
    >
    >http://msdn.microsoft.com/library/default.asp?

    url=/library/en-us/cpref/html/
    >frlrfSystemXmlSerializationXmlRootAttributeClassTopic.asp
    >
    >Hope this help,
    >
    >Luke
    >Microsoft Online Support
    >
    >Get Secure! www.microsoft.com/security
    >(This posting is provided "AS IS", with no warranties,

    and confers no
    >rights.)
    >
    >.
    >
     
    Dima Maltsev, Dec 25, 2003
    #3
  4. Dima Maltsev

    MSFT Guest

    In .NET web service, the serializer is controled by the ASP.NET
    infrastructure, we cannot access the its XMLSerializer object. A work
    around is to modify the SOAP message with SOAP extension before it is sent
    to client. For more detial, you may refer to following article:

    Altering the SOAP Message Using SOAP Extensions
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
    l/cpconAlteringSOAPMessageUsingSOAPExtensions.asp


    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    MSFT, Dec 26, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW5kcmV3RG90SGF5?=

    XmlSerializer - Cannot execute a program csc.exe

    =?Utf-8?B?QW5kcmV3RG90SGF5?=, Jun 13, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,268
    =?Utf-8?B?U2ltb25lIENoaWFyZXR0YQ==?=
    Aug 4, 2004
  2. rabbits77
    Replies:
    0
    Views:
    878
    rabbits77
    Feb 26, 2004
  3. John
    Replies:
    8
    Views:
    926
    iksrazal
    Mar 28, 2005
  4. cmay

    Is Serialization done with Soap or XmlSerializer

    cmay, Jun 8, 2006, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    152
    Josh Twist
    Jun 11, 2006
  5. Peter van der veen

    How to add SOAP header to a SOAP message?

    Peter van der veen, Nov 8, 2006, in forum: ASP .Net Web Services
    Replies:
    6
    Views:
    601
    J. Dudgeon
    Nov 14, 2006
Loading...

Share This Page