XmlSerializer vs SoapFormatter

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
what is the internal difference between them in FW 2.0?
I'm trying to serialize SqlConnectionInfo from SQL SMO and Soap works just
fine but XML throws an exception

SqlConnectionInfo has SerializableAttribute attribute ????
 
lapas,

The two are incredibly different. Internally, they are separate
programs. You should be more worried about what they do.

XML Serialization will "serialize" (I put it in quotes because it is not
truly serialization, it won't always give you an object that has the same
exact internal state as the one that you serialized) just the public
properties of an object.

Using serialization with the SOAP formatter will actually take the field
values of an object (through reflection) and store all of that information
in the stream passed to you.

Depending on what you are doing, one will be more appropriate than the
other. The XML Serializer is used typically for serializing simple types
across web services, or sending the serialized type to other applications
that won't understand the output that the SOAP or binary formatters will
produce.

Using a proper formatter for serialization should be used in other
scenarios, like when talking to other .NET applications.

Hope this helps.
 
Thank you.
Let me ask you this:
if class has attribute [SerializableAttribute] does it mean that objects of
this class can be serialized by either of XmlSerializer or SoapFormatter?

Nicholas Paldino said:
lapas,

The two are incredibly different. Internally, they are separate
programs. You should be more worried about what they do.

XML Serialization will "serialize" (I put it in quotes because it is not
truly serialization, it won't always give you an object that has the same
exact internal state as the one that you serialized) just the public
properties of an object.

Using serialization with the SOAP formatter will actually take the field
values of an object (through reflection) and store all of that information
in the stream passed to you.

Depending on what you are doing, one will be more appropriate than the
other. The XML Serializer is used typically for serializing simple types
across web services, or sending the serialized type to other applications
that won't understand the output that the SOAP or binary formatters will
produce.

Using a proper formatter for serialization should be used in other
scenarios, like when talking to other .NET applications.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

laplas said:
Hello,
what is the internal difference between them in FW 2.0?
I'm trying to serialize SqlConnectionInfo from SQL SMO and Soap works
just
fine but XML throws an exception

SqlConnectionInfo has SerializableAttribute attribute ????
 
lapas,

If a class has the serializable attribute on it, then it means that you
can use any class that implements the IFormatter interface to serialize your
class (this means the SOAP formatter and the binary formatter, or any other
formatter, for that matter).

You can attempt to serialize any instance of any class with the XML
Serializer, but the result is not guaranteed to give you an instance with
the same state when deserialized.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

laplas said:
Thank you.
Let me ask you this:
if class has attribute [SerializableAttribute] does it mean that objects
of
this class can be serialized by either of XmlSerializer or SoapFormatter?

Nicholas Paldino said:
lapas,

The two are incredibly different. Internally, they are separate
programs. You should be more worried about what they do.

XML Serialization will "serialize" (I put it in quotes because it is
not
truly serialization, it won't always give you an object that has the same
exact internal state as the one that you serialized) just the public
properties of an object.

Using serialization with the SOAP formatter will actually take the
field
values of an object (through reflection) and store all of that
information
in the stream passed to you.

Depending on what you are doing, one will be more appropriate than
the
other. The XML Serializer is used typically for serializing simple types
across web services, or sending the serialized type to other applications
that won't understand the output that the SOAP or binary formatters will
produce.

Using a proper formatter for serialization should be used in other
scenarios, like when talking to other .NET applications.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

laplas said:
Hello,
what is the internal difference between them in FW 2.0?
I'm trying to serialize SqlConnectionInfo from SQL SMO and Soap works
just
fine but XML throws an exception

SqlConnectionInfo has SerializableAttribute attribute ????
 
If a class has the serializable attribute, it means you can use only
standard serialization. XmlSerializer dosn't take it in account, it
works in a different way.
 
Back
Top