Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do intra-application communication in .NET

Tags:

c#

.net

windows

What's the best way to pass data from one Windows Forms app (an office plugin) to another (exe written in C#) in C#?

like image 435
OS. Avatar asked Dec 28 '25 14:12

OS.


1 Answers

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:

  1. "Shared Contracts". These are interfaces that describe your services. If you have custom data objects that will be passed between the applications, they should be defined in this assembly as well. This assembly is shared between the client and the server. See "Designing Service Contracts" for more info.
  2. "Service". This assembly is your "exe" and it will reference the contracts and define the classes based on your service contracts. Your app will also host a ServiceClient for your service. The configuration file for this app will define how your ServiceClient will be exposed to the client (available as a web service, tcp, etc). See "Implementing Service Contracts" for more info.
  3. "Client". Your plugin will reference the "Shared Contracts" assembly and will contain service-clients based on the contracts. The client can be auto-generated using the svcutil.exe tool.

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.

like image 198
bryanbcook Avatar answered Dec 30 '25 03:12

bryanbcook



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!