目的: 实现两个独立的Process 之间的通讯。

实现思路: 建立一个WCF Service,然后将其Host到一个Console 程序中,然后在另外一个Console程序中引用WCF的Service,并使用Client调用Interface中定义好的方法。

具体实现:

1. 创建一个WCF Service Libraray。

1.1) File -> New -> New Project -> WCF -> WCF Service Library.)

1.2) 修改Service名和IServcie名为WillWcfService

2. 创建Console程序,并且把WCF Service host 到这个Console程序中。

2.1) 添加引用 System.ServiceModel, 1步中创建的Project (Library).

2.2) 修改App.config ( 添加 Endpoints. ( Address, Binding, Contract ). ) 便捷的方法就是直接复制第一步创建的WCF Service Libraray 项目中的App.config 文件里的内容,这里面已经有提示了。

  <!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->

2.3) 在Console程序中插入代码创建 Host.

            using (ServiceHost host = new ServiceHost(typeof(WillWcfService)))
{
host.Open();
Console.WriteLine("Host started @" + DateTime.Now.ToString());
}

3. 创建Console client 程序。

3.1)运行启动第2步创建的Host程序,启动WCF Service。

3.2)  添加Service引用 (Add Service Reference), 输入在Host程序里App.config中定义的的Address。

3.3)在Console程序里面插入代码创建Client.

            WillWcfServiceReference.WillWcfServiceClient client = new WillWcfServiceReference.WillWcfServiceClient();
string data = client.GetData();
Console.WriteLine("Get data: {0}", data);

最新文章

  1. Portal for ArcGIS安装指南
  2. Serv-U FTP之PASV和PORT模式
  3. Unique Paths II [LeetCode]
  4. 1029c语言文法定义与c程序的推导过程
  5. 算法系列9《MD5》
  6. 收缩Oracle数据文件
  7. ASP.NET缓存全解析1 转自网络原文作者李天平
  8. SQL Server 之 解锁
  9. 现在再开发一个CMS系统还有市场吗?
  10. Vue 爬坑之路(三)—— 使用 vue-router 跳转页面
  11. [代码]JAVA触发器,Spring的quartz配置
  12. 输出一个对象,会默认执行toString()方法
  13. android View层的绘制流程
  14. 【Ubuntu 18.04 搭建VNC服务器】
  15. 在js中网页面写入数据时需要注意的几点
  16. Chromium Embedded Framework (CEF)_3.2171.1979_v20170602_x86.tar.xz
  17. Linq To SQL LEFT OUTER JOIN (Left Join)
  18. HIHOcoder 1403 后缀数组一&#183;重复旋律
  19. OOP⑺
  20. C/C++中带可变参数的函数

热门文章

  1. P1091 合唱队列
  2. Exponentiation POJ-1001
  3. 03-树3 Tree Traversals Again (25 分)
  4. [转] linux alias 编写 函数 脚本
  5. 学习GO第一天,自我感觉可麻利的开干了-GO语言配置、开发、服务器部署
  6. 我3年前开发的IM即时通讯一直没勇气推出,现在智能时代了,有什么可以结合的地方吗?
  7. python的面向对象和类
  8. Linux网络编程服务器模型选择之循环服务器
  9. 【JAVA-WEB】在url上追加sessionid
  10. Scala IDEA for Eclipse里用maven来创建scala和java项目代码环境(图文详解)