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); 
  • 相关阅读:
    如何理解C语言的左结合 和右结合性
    Egg项目使用vscode的debug模式跑单元测试
    为什么要用MongoDB副本集
    理解JS原型和原型链
    防止重复请求攻击
    引擎、编译器和作用域
    闭包原理解析及其应用场景
    树形结构数据完美解决方案
    Excel文件导入导出(基于Nodejs、exceljs)
    架构层面高并发解决方案选择----项目架构模式选择
  • 原文地址:https://www.cnblogs.com/fdyang/p/9838943.html
Copyright © 2011-2022 走看看