Reputation: 358
What's the best way to pass data from one Windows Forms app (an office plugin) to another (exe written in C#) in C#?
Upvotes: 3
Views: 3496
Reputation: 17993
I'll take a wild stab at this and say you probably want the office app to phone home to your exe? In this context, the "exe" is the server and the office app is the client.
If you're using .NET 3.0, WCF is likely your best bet. I would structure the solution into three parts:
Both the "exe" and the "plugin" will require configuration files that define the bindings.
When you want to pass data between client and server, your client will create an object from the "Shared Contracts" assembly and pass it to the service-client. The client's configuration file will figure out where to send the data.
For a step-by-step tutorial on how to create a basic WCF service, check out this Tutorial.
Upvotes: 7
Reputation:
Yup. WCF is the way to go. I recommend checking out iDesign.net to use the InProcFactory class. You can shim up your office class into a service and call into your other application which is hosting a service. The other service can then call back into the office based service.
You can use an IPC endpoint which will make the communication snappy.
-Scott
Upvotes: 2
Reputation: 61223
old-school but it works - using WM_COPYDATA to send messages between windows apps
Upvotes: 1
Reputation: 2220
There are numerous ways to achieve this. I've used named pipes in the past. Support for named pipes are also now built into .NET (as per 3.0?) so it is fairly straight forward.
Upvotes: 1
Reputation: 2531
WCF is one of the easiest ways to do this. You can register a service endpoint in each app, or if one is the service and another is the client you can just use a single service host.
Check out the getting started tutorials.
Upvotes: 1