Serialization


Author
Message
John Frankewicz
John Frankewicz
StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)
Group: Forum Members
Posts: 36, Visits: 65
Our application requires that fields in the database, represented by the business object, be serialized remotely.

Could someone explain the process or point me to a link that explains how this process is done in your framework?

1. Do you have an option where the  serialized data is  stored?

2. Can it be hooked into the .net remoting?

3. How do you select what is serialized? I thought it was done after the object is dropped on the form?

Replies
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Since this my first time working with a MemoryStream, I wonder, should the BO.DeserializeBusinessObject(mem) method take care of repositioning the passed stream to the 0 position?

No.  This could cause all types of issues.  This is the responsibility of the developer.  The same issue would come up with a file.  Most of the time you are not trying to do all of this within the same segment of code, the difference here is that you wrote to it then turned right around and read from it...so in this instance you have to reset the pointer.

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Trent,

Another question about serialization, when we use this command:

pszOutMemByte = Me.bizConnectedClients1.SerializeToByteArray()

Is there a way to add some extra data to the pszOutMemByte variable?  With my communication library, I need to add and End Of Line character to the byte stream and have not found a way to do this, so the communication event will trigger when all data have arrive, so the question is how do I add these character to this byte array pszOutMemByte?



Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Sure.  If I were going to do this I would put it in the front of the byte array with any information that will tell me where the serialized BO starts, etc.  So the beginning of the byte array would be a "header" that contained whatever information that you needed.  This is why I mentioned that resetting the memory stream was not a safe thing to do as other people may be using the memory stream for other things.
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Trent L. Taylor (03/14/2009)
Sure. If I were going to do this I would put it in the front of the byte array with any information that will tell me where the serialized BO starts, etc. So the beginning of the byte array would be a "header" that contained whatever information that you needed. This is why I mentioned that resetting the memory stream was not a safe thing to do as other people may be using the memory stream for other things.


Yes, but can you give me a sample code of how to add the info to the byte array? in my case I will enter the code at the end of the array and the communication library will take care of removing it from the transferred stream.

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Hmmm....it is going to be a lot mroe difficult to add it at the end as you will not know the length of the serialized BO.  That is why a header would work much better as you would know what to expect that tells you what is further down the stream.
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Trent L. Taylor (03/15/2009)
Hmmm....it is going to be a lot mroe difficult to add it at the end as you will not know the length of the serialized BO.  That is why a header would work much better as you would know what to expect that tells you what is further down the stream.

Hi again,

Thanks, but could you provide a quick sample code on how to add this byte to the header?  sorry, but I am really lost here w00t

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Well, it would just be a matter of creating your header in a string format, etc.  Then place that header at the beginning.  For example, I might have an enum that tells me the contents of the byte array in the first element.  In this case, a "1" would indicate a business object.  You could make this as long as you need since you would be in control of the header.  The second part of the header may indicate, in bytes, the length of the serialized BO.

Dim header As String = "1|"
Dim bo() As Byte
Dim mem As New System.IO.MemoryStream()
Dim headerInBytes() As Byte

'-- Serialize the BO to a byte array
bo = MyBO.SerializeToByteArray()

'-- Create the header
header &= bo.Length.ToString()

'-- Place an ending tag on the header
header &= "|"

headerInBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(header)

'-- Create the full byte array
mem.Write(headerInBytes, 0, headerinBytes.Length)

'-- Add the BO to the byte array
mem.Write(bo, 0, bo.Length)

'-- Convert the stream into a byte array
mem.Seek(0, Begin)
Dim r() As Byte = mem.ToArray()

So when you get the byte array on the server side (or whereever) you already know what to expect in the header.  So you can parse it out of the array (convert it back into a string or whatever you expect) and then you know what to do with the rest of the array.

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Thanks a lot Trent, that will get me started.

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
John Frankewicz - 20 Years Ago
Trent L. Taylor - 20 Years Ago
Edhy Rijo - 16 Years Ago
Edhy Rijo - 16 Years Ago
Trent L. Taylor - 16 Years Ago
                         Hi Trent, The problem is with DeserializeBusinessObject. In your test...
Edhy Rijo - 16 Years Ago
                             Yup, it worked. You have to reposition the stream back to the 0...
Trent L. Taylor - 16 Years Ago
                                 [quote][b]Trent L. Taylor (03/12/2009)[/b][hr]Yup, it worked. You have...
Edhy Rijo - 16 Years Ago
                                     [quote] Since this my first time working with a MemoryStream, I...
Trent L. Taylor - 16 Years Ago
                                         Trent, Another question about serialization, when we use this...
Edhy Rijo - 16 Years Ago
                                             Sure. If I were going to do this I would put it in the front of the...
Trent L. Taylor - 16 Years Ago
                                                 [quote][b]Trent L. Taylor (03/14/2009)[/b][hr]Sure. If I were going to...
Edhy Rijo - 16 Years Ago
                                                     Hmmm....it is going to be a lot mroe difficult to add it at the end as...
Trent L. Taylor - 16 Years Ago
                                                         [quote][b]Trent L. Taylor (03/15/2009)[/b][hr]Hmmm....it is going to...
Edhy Rijo - 16 Years Ago
                                                             Well, it would just be a matter of creating your header in a string...
Trent L. Taylor - 16 Years Ago
                                                                 Thanks a lot Trent, that will get me started.
Edhy Rijo - 16 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search