Send Data Over a LAN

J

jp2msft

I need to send object data (an instance of my class) across our internal
Local Area Network (LAN) and process it in a different application on another
PC.

I designed my class so that I could serialize it to the source PC's hard
drive, send the serialized file over the network to the destination PC, save
the data to the destination PC's hard drive, then deserialize the file.

The problem, I found, is that I can't deserialize the file because it needs
the source PC's Assembly information, which isn't there.

So, how can I send my data from Point A to Point B? My class contains mostly
strings and numbers, but some images, too.

I started looking into SOAP, but my manager doesn't want me spending all
this time developing something (AGAIN!) unless I can assure him it is going
to work.

What's my best approach, here?
 
P

Peter Duniho

I need to send object data (an instance of my class) across our internal
Local Area Network (LAN) and process it in a different application on
another
PC.

I designed my class so that I could serialize it to the source PC's hard
drive, send the serialized file over the network to the destination PC,
save
the data to the destination PC's hard drive, then deserialize the file.

The problem, I found, is that I can't deserialize the file because it
needs
the source PC's Assembly information, which isn't there.

Why isn't it? Can you recompile the other application? Wouldn't you have
to, in order to add this feature? How would the other application be
expected to use your object if it doesn't even know about it?

Given that, why not just put your serialized object in a shared assembly
that both applications can use, so that the assembly _is_ present in the
remote computer.

Other alternatives would include using .NET Remoting, WCF, or writing
custom data serialization/deserialization to be used with the lower-level
Socket class. All would require changes to your remote application, so it
seems to me that if you're short on time, leveraging your existing
serialization would probably work best. (Note that you'll run into the
same kind of versioning issues that you would dealing with files).
So, how can I send my data from Point A to Point B? My class contains
mostly
strings and numbers, but some images, too.

I started looking into SOAP, but my manager doesn't want me spending all
this time developing something (AGAIN!) unless I can assure him it is
going
to work. [...]

There's a SOAP formatter available for some of the serialization features
in .NET, but that's more a format issue than a serialization issue.

Pete
 
A

Arne Vajhøj

jp2msft said:
I need to send object data (an instance of my class) across our internal
Local Area Network (LAN) and process it in a different application on another
PC.

I designed my class so that I could serialize it to the source PC's hard
drive, send the serialized file over the network to the destination PC, save
the data to the destination PC's hard drive, then deserialize the file.

The problem, I found, is that I can't deserialize the file because it needs
the source PC's Assembly information, which isn't there.

So, how can I send my data from Point A to Point B? My class contains mostly
strings and numbers, but some images, too.

I started looking into SOAP, but my manager doesn't want me spending all
this time developing something (AGAIN!) unless I can assure him it is going
to work.

What's my best approach, here?

Serialized data only contains the data and a reference to the class
definition not the actual class definition.

The easiest solution is just to have the classes used for communication
in a separate DLL that is present in both ends.

You could try if you can get the assembly remotely, but I have
never seen that done for .NET.

Or you could switch from serialization to a data format that
does not require the same class in both ends.

POX seems obvious. But even JSON could be used.

Arne
 
J

jp2msft

Hi Pete and Arne,

The methods that serialize and deserialize are in the same file that
contains the class that defines the data. That file is referenced from both
projects (they are in the same VS2005 solution), but PC B is not able to
deserialize a file that PC A serialized, it seems.

POX=Plain Old XML? Not sure how I'd get images sent across that way. Got an
example? I need to be able to store it all on the other side.
 
J

Joe Fawcett

jp2msft said:
Hi Pete and Arne,

The methods that serialize and deserialize are in the same file that
contains the class that defines the data. That file is referenced from
both
projects (they are in the same VS2005 solution), but PC B is not able to
deserialize a file that PC A serialized, it seems.
Why not? Can you show a small example of how you are trying to deserialize?
 
M

Mr. Arnold

jp2msft said:
How do I send files across with XML serialization? Examples? Links?

:

Regardless, if this is an object, you're talking about and it's jp2msft.cs,
then jp2msft.cs must be known on both ends. The serialize and desterilize
must know what the object is that it serializing from and what the object is
that it's serializing to.

You're better off I would think in putting the data in a dataset and sending
it serializing and deserializing the dataset on both ends, as
typeof(dataset) is know on both ends, right?


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4279 (20090726) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
J

jp2msft

Close. The file is called Global.cs, and it is accessed as a linked reference
in both Projects, so both projects know of the object.

Still, writing all the data to a dataset would have been much simpler than
the class I had to design. I'll look into that!

Thanks, Arnold!
 
P

Peter Duniho

Hi Pete and Arne,

The methods that serialize and deserialize are in the same file that
contains the class that defines the data. That file is referenced from
both
projects (they are in the same VS2005 solution), but PC B is not able to
deserialize a file that PC A serialized, it seems.

Then we need more information. Normally, that should work just fine. If
you want pursue that option, you should provide a concise-but-complete
code example that reliably demonstrates the problem.
POX=Plain Old XML? Not sure how I'd get images sent across that way. Got
an
example? I need to be able to store it all on the other side.

If XML, a common approach is to convert to Base64 and put the resulting
text in the XML.

Of course, if you're defining your own application-level serialization
protocol, you have the luxury of being able to include things that are not
necessarily pure XML, or pure binary. For example, you could define your
protocol to send XML where appropriate (e.g. information where it makes
sense for it to be human-readable), but then transmit raw bytes for things
like image files.

If and when you abandon the pre-defined approaches, like .NET
serialization, remoting, WCF, etc. then you have the freedom to do pretty
much whatever you want. It may require more complicated code than the
built-in features, but that's at least rewarded by giving you more
flexibility.

Of course, flexibility sometimes means having enough rope to hang yourself
with; it's not always a good thing. :)

Pete
 
A

Arne Vajhøj

jp2msft said:
How do I send files across with XML serialization? Examples? Links?

XmlSerializer ser = new XmlSerializer(typeof(SomeClass));
ser.Serialize(somewriter, someobject);

and

XmlSerializer ser = new XmlSerializer(typeof(SomeClass));
SomeClass someobject = (SomeClass)ser1.Deserialize(somereader);

but I don't think it will fix your problem.

Arne
 
C

Chris

Close. The file is called Global.cs, and it is accessed as a linked reference
in both Projects, so both projects know of the object.

That's most likely your problem. You might have the same file linked,
but they are compiled into two different assemblies and are not the
same class, even if they have the same name and structure.

You should compile the class into a single assembly and then reference
that *same* assembly in both projects.

Chris
 

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

Top