GenericPrincipal serialization.

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

Guest

Once a user has signed in I would like to cache the authentication that has
happened so I need to serialize GenericPrincipal. I would like to serailize
this object to a string that will be stored in a database untill neeed later.
The problem that I am running into is that when I try to serializae
GenericPrincipal I get an error indicating that GenericPrincipal cannot be
serialized because there is no default constuctor. Anybody have any ideas for
work arounds?

Thank you.

Kevin Burton
(e-mail address removed)
 
The GenericPrincipal class is marked with SerializableAttribute. This means
that you can serialize a GenericPrincipal object to any stream (e.g.
FileStream or MemoryStream) using the classes SoapFormatter or
BinaryFormatter. These formatters do not require a default constructor as
does XmlSerializer. For example:

static void SerializePrincipal(IPrincipal prin, Stream s)
{
SoapFormatter formatter = new SoapFormatter();
formatter.Serialize(s, prin);
}

HTH, Jakob.
 
Thank you very much. This pretty much solves the serialization problem.

Now I have a question on deserialization. The serialized data of necessity
will reside in an XML document. Because of this I need to enclose the
serialized data in a CDATA section. So the element node would look like:

<GenericPrincipal><![CDATA[ ..... ]]></GenericPrincipal>

Where ..... is the serialized GenericPrincipal as out from the SOAP
formatter. When I retrived the element value I will have something like:

<![CDATA[ ..... ]]>

My question is how do I remove the CDATA stuff from around the serialized
value so I can deserialize just on the value?

Thank you for your suggestions.

Kevin Burton
 
Hi Kevin,

Why do you need to use a CDATA section? If you are using the SoapFormatter,
the serialized data will already be XML.

Regards, Jakob.


Kevin Burton said:
Thank you very much. This pretty much solves the serialization problem.

Now I have a question on deserialization. The serialized data of necessity
will reside in an XML document. Because of this I need to enclose the
serialized data in a CDATA section. So the element node would look like:

<GenericPrincipal><![CDATA[ ..... ]]></GenericPrincipal>

Where ..... is the serialized GenericPrincipal as out from the SOAP
formatter. When I retrived the element value I will have something like:

<![CDATA[ ..... ]]>

My question is how do I remove the CDATA stuff from around the serialized
value so I can deserialize just on the value?

Thank you for your suggestions.

Kevin Burton

Jakob Christensen said:
The GenericPrincipal class is marked with SerializableAttribute. This means
that you can serialize a GenericPrincipal object to any stream (e.g.
FileStream or MemoryStream) using the classes SoapFormatter or
BinaryFormatter. These formatters do not require a default constructor as
does XmlSerializer. For example:

static void SerializePrincipal(IPrincipal prin, Stream s)
{
SoapFormatter formatter = new SoapFormatter();
formatter.Serialize(s, prin);
}

HTH, Jakob.
 
It is a problem with including XML in an XML document. I want the serialized
XML from the SOAP formatter to be associated with one tag in the "master" XML
document. If I don't wrap the serialized SOAP data with CDATA then loading
the "master" XML document seems to get confused.

Jakob Christensen said:
Hi Kevin,

Why do you need to use a CDATA section? If you are using the SoapFormatter,
the serialized data will already be XML.

Regards, Jakob.


Kevin Burton said:
Thank you very much. This pretty much solves the serialization problem.

Now I have a question on deserialization. The serialized data of necessity
will reside in an XML document. Because of this I need to enclose the
serialized data in a CDATA section. So the element node would look like:

<GenericPrincipal><![CDATA[ ..... ]]></GenericPrincipal>

Where ..... is the serialized GenericPrincipal as out from the SOAP
formatter. When I retrived the element value I will have something like:

<![CDATA[ ..... ]]>

My question is how do I remove the CDATA stuff from around the serialized
value so I can deserialize just on the value?

Thank you for your suggestions.

Kevin Burton

Jakob Christensen said:
The GenericPrincipal class is marked with SerializableAttribute. This means
that you can serialize a GenericPrincipal object to any stream (e.g.
FileStream or MemoryStream) using the classes SoapFormatter or
BinaryFormatter. These formatters do not require a default constructor as
does XmlSerializer. For example:

static void SerializePrincipal(IPrincipal prin, Stream s)
{
SoapFormatter formatter = new SoapFormatter();
formatter.Serialize(s, prin);
}

HTH, Jakob.

:

Once a user has signed in I would like to cache the authentication that has
happened so I need to serialize GenericPrincipal. I would like to serailize
this object to a string that will be stored in a database untill neeed later.
The problem that I am running into is that when I try to serializae
GenericPrincipal I get an error indicating that GenericPrincipal cannot be
serialized because there is no default constuctor. Anybody have any ideas for
work arounds?

Thank you.

Kevin Burton
(e-mail address removed)
 
Back
Top