Hi.
I understand that the smartphone/.NET CF (1.1/2.0) does not have a way to send objects using TCPClient/listener (in other words, from PC to phone) but can send strings.
I know you could use a web service, and pass objects to and from :)
I am wondering if there is any way I can pass an object from the PC (not using webservice but a C# winform app) to the smartphone and back

passing objects
iGNOSaurus
There's a sample on MSDN for XML Serializer:
http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpref/html/frlrfsystemxmlserializationxmlserializerclasstopic.asp
Yes, XML serializer on NETCF is compatible with desktops. Classes you're serializing should be available on both sides.
Prze
Hi again.
I am finally getting to do this right now. I have my own messaging system on the client mobile device which is pretty much a string checker if you like.
I can send the serialized object no problem but the client recieving it has a bit of a problem.
since this is my code for the incoming connection listener on the client:
.. byte[] theIncomingDataBuffer = new byte[256];
int theData = this.theNetworkStream.Read(theIncomingDataBuffer, 0, theIncomingDataBuffer.Length);
this.theIncomingDataManager.DoAnalyzeData(System.Text.Encoding.ASCII.GetString(theIncomingDataBuffer, 0, theData));
the buffer will of course fill it up to 256 bytes and then proceed with the next chunk and so on - in other words it will recieve the looooooong information in chunks and not one complete string. Sure, we can increase the buffer size but is this good enough since we do not know how big the data will be
since I have no idea, nor would anyone really, on how long the xml serialization will be in length, how can i manage this for the client so the client can fully deal with the incoming serialization (and then do deserialization)
I would prefer to use best practice/the proper way of doing this. I don't know if (again prefer not to do it this way unless this is the only way) - I should use some flag and set the client reciever to raise a flag when xml data is being set (look at xml start string) and when xml data has stopped recieving, then send an "end" flag or something
I hope this makes sense.
eriks70012
interesting.
Since my application will send strings and other stuff to and from it, what is the best way of sending this file or data using the memorystream or whatever via the TCP sock How can I determine if the data being recieved is of a file or just a simple string
Can't wait to experiment with this! Thanks again!
Arshvinder Bhatia
Simply read from the stream byte by byte until you figure out what you've got, then pass stream to deserializer.
benbino
cool, many thanks! Much appreciated for your guidence. I will get back if I have any problems.
marco.ragogna
Hello Ilya,
Is there any sample code that you can point me to for building a custom binary serialization mechanism using BinaryReader and BinaryWriter for the suggested better performance for the compact framework
Thanks in advance for any help you can provide :)
Bob
a. johns
If I may ask....
how do I make this work
say for example, I have an object - its type is "ClassA"
I have an instance of this object:
ClassA theClass = new ClassA();
I wish to then pass this object, from the PC (.NET 2.0), to the mobile device (CF 2.0) - would this be possible
Matt Spy
Correct, you need to send XML over the wire and receive it on another end. Note serializer can work with streams. That can be file stream, memory stream or network stream. For example, if you using sockets you can save data using memory stream and transmit buffer to the destination as you normally would do with byte array.
ebj
Objects are not actually going through the wire. Instead they are transformed into bunch of bytes, which are actually transmitted and restored back on another side. That process is known as serialization/deserialization and performed by serializers. Basically what serializer does – it goes through all members of the class, converts them into binary data or XML elements. Receiving end converts data back and sets members to the original values.
XML serializer is available on NETCF V2 to serialize your objects and pass resulting XML via sockets. For V1 you could implement custom serialization on objects you're planning to send or you could try this serializer:
http://www.freewebs.com/compactFormatter/downloads.htmlNikiR
thanks again
this is just awesome stuff!!!
martinkwong
yes ... thats what i had at the back of my mind! Excellent stuff, Microsoft rocks once again :D
thanks!
Aiwa
just to add - im actually now using .NET CF 2.0 and well, using XmlSerialization - awesome stuff!!!!
as for the 1.0 owners, including myself too for my other mobile device, still trying to work on it soon!
I do recommend using .NET 2.0 of course and taking advantage of XmlSerializer
Vannie
Thank-you, I will take a look at this
once again Microsoft rock, always a great piece of technology there
Reading through it, all sounds fantastic but to me, I guess I still (once serialized the objects) need to send this xml file across to the other end
Bharti Reddy
You can use serializer on strings too. Deserializer would then figure our what it is (or throw if it could not). Of you could implement your own mechanism to determine what exactly you're sending.
By the way, consider using MSMQ/System.Messaging instead of sockets. That would save you a lot of work and ensure reliable delivery.