soap message

T

Tony Johansson

Hi!

Below I have a simple console program that is using the SoapFormatter to
serialize an object ShoppingCartItem into file.

Assume that we serialize this object by using SoapFormatter and sent it away
so it can be deserialized in another application on another computer. I mean
when we deserialize we do this
item = (ShoppingCartItem)sf.Deserialize(fs);
knowing that the object is a ShoppingCartItem that is going to be
deserialized

Now to my question when writing code on the receiving application that will
deserialize the object
how is it possible to write code that know in advance what type of object
that we have so a suitable cast can be done as we do here
item = (ShoppingCartItem)sf.Deserialize(fs);
Can somebody explain this ?

public static void Main(string[] args)
{
ShoppingCartItem item = new ShoppingCartItem(4370, 423.50M, 1);
FileStream fs = new FileStream("Test.sop", FileMode.Create);
SoapFormatter sf = new SoapFormatter();
sf.Serialize(fs, item);
fs.Close();

fs = new FileStream("tonyTest.bin", FileMode.Open);
item = (ShoppingCartItem)sf.Deserialize(fs);
fs.Close();
}

//Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top