zoukankan      html  css  js  c++  java
  • (WCF) 利用WCF实现两个Process之间的通讯。

    目的: 实现两个独立的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(8);
                Console.WriteLine("Get data: {0}", data); 
  • 相关阅读:
    针对安卓java入门:方法的使用
    ES6里关于字符串的拓展
    ES6里关于数字的拓展
    项目笔记:导出XML和导出全部XML功能
    项目笔记:中文转拼音工具类
    深入理解dataset及其用法
    前端插件实现图片懒加载
    Java里日期转换及日期比较大小
    iframe.contentWindow 属性:关于contentWindow和contentDocument区分
    GROUP BY 和 GROUP_CONCAT的使用
  • 原文地址:https://www.cnblogs.com/fdyang/p/9838943.html
Copyright © 2011-2022 走看看