Reputation: 20378
Is there a simple way to send objects between applications using C#? The objects will not always be the same, there would be (for example) a "Request" and "Response" class and each side of the connection would have a sort of switch statement which decides which object has been received.
Is there a simple way to achieve something like this in C# without the need for 3'rd part libraries?
Upvotes: 1
Views: 1816
Reputation: 13055
I'd always try to look at the problem as sending data between applications, not objects. Distributed object models almost always end in tears, as you don't really have shared state.
Upvotes: 0
Reputation: 17719
The definition of "simple" also depends on your requirements. Built-in functionality (eg. WCF) would not be classified as 3rd party libraries and therefore provide a simple way to securely send objects between C# applications. WCF can automatically generate proxies for you so all you have to do is define your data contracts and expose your service. You can add a service reference inside visual studio and the methods are exposed.
I will re-iterate, it really depends on what you want to do, to determine what the simplest solution is.
Upvotes: 1
Reputation: 6477
WCF could work here, you just need to set up an interface describing the objects you are going to pass. Here is a good tutorial on using WCF for interprocess communication.
Upvotes: 4
Reputation: 14234
If you do not need to send the full binary object (with logic instructions) you can serialize the request and response classes to XML and send over the text via streams.
Upvotes: 2
Reputation: 754725
The easiest way to accomplish over a raw TCP connection this is to create a DLL which is referenced by the applications on both sides of the connection. Put all of your communication classes in this DLL and mark every type as Serializable
. This enables the objects for binary serialization and hence an easy conversion into a byte[]
which can be passed directly through the TCP connection.
If you have a bit more flexbility you may want to consider something a bit higher level though like Remoting Services or WCF
Upvotes: 3
Reputation: 2724
.NET remoting does more or less what you want, and you can use your interface classes as the classes which do the "switch statement"
http://msdn.microsoft.com/en-us/library/kwdt6w2k(VS.71).aspx
Upvotes: 2