Home All Groups Group Topic Archive Search About

GenericPrincipal serialization.

Author
20 Feb 2005 9:05 PM
Kevin Burton
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
kbur***@visa.com
Author
21 Feb 2005 8:19 AM
Jakob Christensen
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.

Show quoteHide quote
"Kevin Burton" wrote:

> 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
> kbur***@visa.com
>
Are all your drivers up to date? click for free checkup

Author
21 Feb 2005 4:21 PM
Kevin Burton
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

Show quoteHide quote
"Jakob Christensen" wrote:

> 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.
>
> "Kevin Burton" wrote:
>
> > 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
> > kbur***@visa.com
> >
Author
22 Feb 2005 7:55 AM
Jakob Christensen
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.


Show quoteHide quote
"Kevin Burton" wrote:

>
> 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" wrote:
>
> > 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.
> >
> > "Kevin Burton" wrote:
> >
> > > 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
> > > kbur***@visa.com
> > >
Author
22 Feb 2005 4:55 PM
Kevin Burton
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.

Show quoteHide quote
"Jakob Christensen" wrote:

> 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" wrote:
>
> >
> > 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" wrote:
> >
> > > 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.
> > >
> > > "Kevin Burton" wrote:
> > >
> > > > 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
> > > > kbur***@visa.com
> > > >

Bookmark and Share