如何做到在.NET应用程序内的通信 [英] How to do intra-application communication in .NET

查看:106
本文介绍了如何做到在.NET应用程序内的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是从一台Windows传递数据的最佳方式窗体应用程序(办公室插件)复制到另一个文件(EXE写在C#)在C#中?

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

推荐答案

我会采取一种野生刺在此,说你可能想在办公室应用程序来的手机之家的你的exe文件?在此背景下,执行是在服务器和办公室应用程序是客户端。

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.

如果您使用的是.NET 3.0,WCF可能是你最好的选择。我将结构化的解决方案分为三个部分:

If you're using .NET 3.0, WCF is likely your best bet. I would structure the solution into three parts:

  1. 在共享合同。这是描述您的服务接口。如果有,将在应用程序之间传递自定义数据对象,就应该在这个大会被定义为好。该组件在客户端和服务器之间共享。请参阅设计服务合同获取更多信息。
  2. 在服务。该组件是你的EXE,它会引用合同和定义基于服务合同的类。您的应用程序还将举办一个ServiceClient为您服务。此应用程序的配置文件定义如何ServiceClient将暴露给客户端(可以作为一个网络服务,TCP等)。请参阅实施服务合同获取更多信息。
  3. 在客户。你的插件将引用共享合同组件,将包含基于合同的服务客户。客户端可以自动生成使用svcutil.exe的工具。
  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.

有关一步一步的教程就如何创建一个基本的WCF服务,的看看这个教程

For a step-by-step tutorial on how to create a basic WCF service, check out this Tutorial.

这篇关于如何做到在.NET应用程序内的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆