Franklin, using (or Imports) System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Soap;
There actually needs to be a reference set to the System.Runtime.Serialization.Formatters.Soap library in your project references (C: \WINNT\Microsoft.NET\Framework\v1.0.3705\System.Runtime.Serialization.Formatters.Soap.dll) According to the docs "The System.Runtime.Serialization.Formatters namespace provides common enumerations, interfaces, and classes that are used by serialization formatters." The Soap formatter's in it's own file. I guess, implementing some of the Serialization.Formatters definitions. More info in :ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemRuntimeSerializationFormattersSoapSoapFormatterClassTopic.htm in the Framework documentation Steve Holak Senior Software Architect Brokerage Concepts IS Dept. 610-491-4879 email: [EMAIL PROTECTED] franklin gray <franklin.w.gray@VITALTH To: [EMAIL PROTECTED] OUGHT.COM> cc: Sent by: dotnet Subject: Re: [DOTNET] Object serialization to string representation discussion <[EMAIL PROTECTED] COM> 05/21/2002 11:13 AM Please respond to dotnet discussion Thanks for the code Steve, but I have a question. What namespace does the SoapFormatter come from? I tried to do this from the help files but this namespace doesn't seem to exist. Do I need to add a reference to something? Imports System.Runtime.Serialization.Formatters.Soap -----Original Message----- From: Steve Holak [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 21, 2002 9:55 AM To: [EMAIL PROTECTED] Subject: Re: [DOTNET] Object serialization to string representation Thanks to all who replied to this; I took it all to heart and played with various scenarios based on our needs (and the intent was, as Brent stated, simply to persist the object to a database for a while and re-hydrate it later), and decided to use the SoapFormatter. I wrote a little wrapper class to handle the serialization for the application; I've included the simplified code below for anyone interested. Thanks again to everyone. public class Serialization { public static string SoapSerialize(object o) { string results; //Serialize the object Stream stream=new MemoryStream(); SoapFormatter formatter=new SoapFormatter(); formatter.Serialize(stream,o); //return the string StreamReader sr =new StreamReader(stream); sr.BaseStream.Seek(0, SeekOrigin.Begin); results=sr.ReadToEnd(); sr.Close(); return results; } public static object SoapDeserialize(string soap) { object o; Stream stream=new MemoryStream(Encoding.UTF8.GetBytes(soap)); SoapFormatter formatter=new SoapFormatter(); o=formatter.Deserialize(stream); stream.Close(); return o; } } To use : private void SerializeMyself() { string serialized=Serialization.SoapSerialize(this); // call the UploadToDatabaseFunction(serialized); } private MyObjectType Deserialize()//summarized. You could make this more flexible and generic by eliminating the //cast or passing in the type, etc,. { //string serialized=GetObjectFromDatabaseFunction(some identifier); return (MyObjectType) Serialization.SoapDeserialize(serialized); } Steve Holak Senior Software Architect Brokerage Concepts IS Dept. 610-491-4879 email: [EMAIL PROTECTED] "Brent E. Rector" <[EMAIL PROTECTED] To: [EMAIL PROTECTED] > cc: Sent by: dotnet Subject: Re: [DOTNET] Object serialization to string representation discussion <[EMAIL PROTECTED] VELOP.COM> 05/20/2002 05:49 PM Please respond to dotnet discussion IMO, the SoapFormatter is a better choice because it can represent all serializable .NET types while the XML serializer is quite restricted as to the types it supports. Especially if I correctly understood he intends to save the string dta to a database and, I assume, rehydrate it later on a .NET system. -- Brent Rector, .NET Wise Owl Demeanor for .NET - an obfuscation utility http://www.wiseowl.com/Products/Products.aspx -----Original Message----- From: franklin gray [mailto:[EMAIL PROTECTED]] Sent: Monday, May 20, 2002 2:45 PM To: [EMAIL PROTECTED] Subject: Re: [DOTNET] Object serialization to string representation or doing something like this.... Public Function GetXML() as string Dim serializer As New System.Xml.Serialization.XmlSerializer(GetType(YOUROBJECTTYPEHERE)) Dim writer As New System.IO.StringWriter() Dim Obj As YOUROBJECTTYPEHERE Obj = Me serializer.Serialize(writer, Obj) Dim s As String s = writer.ToString writer.Close() Return s End Function -----Original Message----- From: Brent E. Rector [mailto:[EMAIL PROTECTED]] Sent: Monday, May 20, 2002 4:35 PM To: [EMAIL PROTECTED] Subject: Re: [DOTNET] Object serialization to string representation Well, you are using the "Binary" formatter to write the state of your object to the stream. But you subsequently try and read the binary data as a string. You'd have better luck using the SoapFormatter. -- Brent Rector, .NET Wise Owl Demeanor for .NET - an obfuscation utility http://www.wiseowl.com/Products/Products.aspx -----Original Message----- From: Steve Holak [mailto:[EMAIL PROTECTED]] Sent: Monday, May 20, 2002 2:13 PM To: [EMAIL PROTECTED] Subject: [DOTNET] Object serialization to string representation I'm trying a test function to serialize an object to a string (to eventually upload the string to a database for storage). The object serializes just fine to disk creating a Stream as a File.IO. What I'm encountering is trying to serialize to a MemoryStream and reading it back with a StreamReader; in the code below the string "test" is always empty ("") The "this" reference is the object itself which contains the serialization implemetation. What am I missing, and is there a simpler way to return the string representation of a serialized object without writing to disk? Stream stream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream,this);//this is the object saving itself to the db. StreamReader sr =new StreamReader(stream); sr.BaseStream.Seek(0, SeekOrigin.Begin); //test always shows "" string test=sr.ReadToEnd(); stream.Close(); TIA Steve Holak Senior Software Architect Brokerage Concepts IS Dept. 610-491-4879 email: [EMAIL PROTECTED] You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.