Unable to pass Dictionary class instance over Webservice

Unable to pass Dictionary class instance over Webservice

Post by TmlyYW5qYW » Thu, 08 Jun 2006 21:43:02

Getting serialization error. The class implements ISerializable.
Is there any resolution to this.


Unable to pass Dictionary class instance over Webservice

Post by Kevin Spen » Fri, 09 Jun 2006 00:37:26

Hi Niranjan,

XML Serialization is a type of Serialization. But most types of
Serialization are not XML Serialization, and not everything marked as
Iserialzable can be serialized as XML. Let me clarify a bit, and I'll leave
you with a couple of online references you can study.

Serialization (the general term) is the process of transforming an object to
a stream or an array of bytes (the 2 are almost the same). I prefer to refer
to it as "Binary" Serialization because it makes it easier to differentiate
between Serialization and XML Serialization, but I can understand why
Microsoft does not, because in fact, both XML Serialization and
Serialization are used to serialize binary objects, and Serialization can be
used to serialize data as a string rather than simply an array of bytes (2
very similar types as well, but not quite as closely related). But the
differences, while seemingly subtle, are quite important.

First, XML Serialization *always* serializes data to an XML stream or
string. "Binary" Serialization does not. "Binary" Serialization simply
serializes the data as a stream or string, without XML markup. It is used to
serialize classes to a file system, or in Remoting, or any other process
which does not use XML.

Second, the difference between a string and an array of bytes is that a
string can be text of any encoding, character set, or language. Some strings
(like ASCII strings, for example) store a character in a single byte.
Others, like Unicode, store a character in 2, 3 or 4 bytes. A string must be
"translated" from a sequence of bytes into a sequence of characters, using
the encoding, character set, and language of the string. All characters in a
string are exactly the same number of bytes each.

A binary array of bytes is simply that: an array of bytes. The data in the
array may be comprised of data that is of nearly any length, in various
combinations. So, a binary array is "translated" by using some form of
schema that indicates what the types stored in the array are, and the order
in which they are stored.

Bottom line is, you have to handle each of these in a different way. Here
are a couple of references on these general topics:


Now, while most types that implement ISerializable *can* be serialized as
XML, classes derived from System.Collections.IDictionary cannot. The good
news is, there is a way around this. It can be done by wrapping an
IDictionary class instance in another class and implementing
System.Xml.IXmlSerializable. There is a piece that details this in the
following MSDN magazone article:



Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

A lifetime is made up of
Lots of short moments.


Unable to pass Dictionary class instance over Webservice

Post by TmlyYW5qYW » Fri, 09 Jun 2006 14:52:01

i Kevin,

Thanks for the info. I was able to implement the solution and it worked.


"Kevin Spencer" wrote: