(WCF) 利用WCF实现两个Process之间的通讯。
2024-09-01 10:35:28
目的: 实现两个独立的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);
最新文章
- Portal for ArcGIS安装指南
- Serv-U FTP之PASV和PORT模式
- Unique Paths II [LeetCode]
- 1029c语言文法定义与c程序的推导过程
- 算法系列9《MD5》
- 收缩Oracle数据文件
- ASP.NET缓存全解析1 转自网络原文作者李天平
- SQL Server 之 解锁
- 现在再开发一个CMS系统还有市场吗?
- Vue 爬坑之路(三)—— 使用 vue-router 跳转页面
- [代码]JAVA触发器,Spring的quartz配置
- 输出一个对象,会默认执行toString()方法
- android View层的绘制流程
- 【Ubuntu 18.04 搭建VNC服务器】
- 在js中网页面写入数据时需要注意的几点
- Chromium Embedded Framework (CEF)_3.2171.1979_v20170602_x86.tar.xz
- Linq To SQL LEFT OUTER JOIN (Left Join)
- HIHOcoder 1403 后缀数组一&#183;重复旋律
- OOP⑺
- C/C++中带可变参数的函数
热门文章
- P1091 合唱队列
- Exponentiation POJ-1001
- 03-树3 Tree Traversals Again (25 分)
- [转] linux alias 编写 函数 脚本
- 学习GO第一天,自我感觉可麻利的开干了-GO语言配置、开发、服务器部署
- 我3年前开发的IM即时通讯一直没勇气推出,现在智能时代了,有什么可以结合的地方吗?
- python的面向对象和类
- Linux网络编程服务器模型选择之循环服务器
- 【JAVA-WEB】在url上追加sessionid
- Scala IDEA for Eclipse里用maven来创建scala和java项目代码环境(图文详解)