1

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?

6 Answers 6

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This solution really is quick and easy to do.
3

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

1 Comment

Serialization via Tcp stream would be my first choice over Remoting. And WCF can be way more intense than what this operation requires. Depends on the overall usage, requirements, and/or expectations.
2

.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

4 Comments

This does work, but you will incur a large(r) overhead in space and network traffic.
.net remoting is a predecessor to WCF. Seriously consider using WCF while considering .net remoting. The value of higher level transporting, the value of the ease for de/serializing objects, and IDE support outways the overhead.
@steven - Serializing to XML would create a far larger payload, with just as coarsely grained messaging. .NET remoting, from what I remember (can) use(s) byte streams for sending over the serialized form of an object, and therefore has a smaller payload. @Russell - agreed, I was going to mention about WCF, but the OP seemed to imply they wanted something a bit more "custom". The use of WCF is very elegant too.
2

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.

Comments

1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.