|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
GenericPrincipal serialization.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 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 > 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 > > 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 > > > 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 > > > >
Other interesting topics
strong naming fails if delay signed
When does a Windows Form create it's message processing thread CLR Bug ?! Interlocked vs Mutex efficiency GUID for .Net framework Release date for .NET 2.0 on_Windows_98 Including MSDE in Windows package, containing C# app Protecting code Update for .NET Framework - "you can't get there from here" |
|||||||||||||||||||||||