XmlSerializer in SOAP message

D

Dima Maltsev

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
 
M

MSFT

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.)
 
D

Dima Maltsev

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
 
M

MSFT

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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top