all groups > dotnet web services enhancements > december 2004 >
You're in the

dotnet web services enhancements

group:

serializing string property (which contains XML) to SOAP message..


serializing string property (which contains XML) to SOAP message.. Kirk Marple
12/23/2004 2:01:02 AM
dotnet web services enhancements:
i have a C# class which has a string property, and i'm serializing this class
into a SOAP message.

the string property actually contains another object serialized to XML, and
i'm finding that this property in the SOAP body is getting HTML-encoded.

i.e. <Array><Item /></Array> is becoming <Array> etc.

i can't seem to find a XmlXXXAttribute which would apply in this case to
prevent this from happening.

is there a way to pass the XML thru un-encoded?

i'm using a string property as an opaque way of storing other serialized
classes... would it make more sense to use an XmlDocument or XmlNode
property, and would that serialize into the SOAP body correctly?

thanks,
Re: serializing string property (which contains XML) to SOAP message.. Christoph Schittko [MVP]
12/27/2004 11:34:35 AM
Kirk,

Are you working with an ASP.NET Web service or SoapClient/SoapService
pair of classes?

Regardless, strings will always be encoded according to the character
entity encoding rules for XML [0] (which are slightly different from
HTML, btw).

I'm not sure I've seen anything as you describe like:

[quoted text, click to view]

How did you determine that? Did you look at an output trace or what kind
of editor are you using?

[quoted text, click to view]

Yes, typing your parameter or return value as XmlNode or XmlDocument
instead of string will serialize the raw XML into the message. Have you
tried to serialize the objects directly into the message or do you have
to store them in strings?


HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko

[0] http://www.w3.org/TR/2004/REC-xml-20040204/#charsets

[quoted text, click to view]
Re: serializing string property (which contains XML) to SOAP messa Kirk Marple
12/27/2004 12:03:03 PM
hi Christoph,

I'm working with SoapSender/SoapService.

The newsgroup posting munged my text. This should have read:

[quoted text, click to view]

So it was HTML-encoding the text. I found this from overridding the
SoapSender and SoapService methods to look at the Body property.

I'm going to change my property type to XmlElement or XmlDocument and that
should solve my problem.

Thanks for the help,
Kirk

[quoted text, click to view]
Re: serializing string property (which contains XML) to SOAP messa Kirk Marple
12/27/2004 1:11:03 PM
Yep, that's exactly what i'm using.

It just happened to be that my body object has a string-valued property
which i wanted to contain raw XML to be serialized into the body.

using an XmlElement-valued property instead should work for me. i haven't
gotten a chance to try it out yet though.

Thanks,
Kirk

[quoted text, click to view]
Re: serializing string property (which contains XML) to SOAP message.. Christoph Schittko [MVP]
12/27/2004 3:02:22 PM
Kirk,

I'm not sure if this will help, but since you mentioned that you are
working with the SoapSender class: You may want to take a look at the
SoapSender.Send() method in conjunction with the
SoapEnvelope.SetBodyObject() method. It allows you to do some of the
work "by hand" and it might save you some intermediate
serialization/deserialization steps.

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko

[quoted text, click to view]
RE: serializing string property (which contains XML) to SOAP message.. danro NO[at]SPAM microsoft.com
1/4/2005 10:12:57 PM
Hi Kirk

If it were me, I'd make the property an object type, and use a number of
XmlIncludeAttribute adornments on the class that contains that property -
one per any of the possible types. If you need an expandable number of
types and not want to recode as you expand the number of class types that
you are masking, then I'd go for XmlNode as the property type, and
serialize your class instances to XmlDocument before assigning them.

For small #'s of substitutions of types that don't derive from the same
root, (in XML this is the substitution group construct), go with object as
the property type and use the XmlInclude markup.

For known #'s of substitutions of types that all derive from a given base
class, make the property type the abstract base class type, and use the
XMlInclude markup - one attribute for each possible concrete class instance.

The result of doing this will be a clean serialization and deserialization.
If you can avoid using XML in our classes, you'll get full class promotion
on the deserialize step - always nice because you can then use reflection
to see what type of class is there, cast it appropriately and then use the
members directly.

I hope this helps

Dan Rogers
Microsoft Corporation
--------------------
Thread-Topic: serializing string property (which contains XML) to SOAP
message..
thread-index: AcTo1k84MpOl5L4qTFmyQzKgZKxJJg==
X-WBNR-Posting-Host: 24.19.227.251
From: "=?Utf-8?B?S2lyayBNYXJwbGU=?=" <KirkMarple@discussions.microsoft.com>
Subject: serializing string property (which contains XML) to SOAP message..
Date: Thu, 23 Dec 2004 02:01:02 -0800
Lines: 19
Message-ID: <8E867D3F-C8ED-4BD7-8D99-0EA45BDC3307@microsoft.com>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.webservices.enhancements
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.webservices.enhancements:5246
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices.enhancements

i have a C# class which has a string property, and i'm serializing this
class
into a SOAP message.

the string property actually contains another object serialized to XML, and
i'm finding that this property in the SOAP body is getting HTML-encoded.

i.e. <Array><Item /></Array> is becoming <Array> etc.

i can't seem to find a XmlXXXAttribute which would apply in this case to
prevent this from happening.

is there a way to pass the XML thru un-encoded?

i'm using a string property as an opaque way of storing other serialized
classes... would it make more sense to use an XmlDocument or XmlNode
property, and would that serialize into the SOAP body correctly?

thanks,
AddThis Social Bookmark Button