(WCF)利用WCF实现两个Process之间的通讯。-创新互联

目的: 实现两个独立的Process 之间的通讯。(WCF)利用WCF实现两个Pr
ocess之间的通讯。

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

目前创新互联公司已为近1000家的企业提供了网站建设、域名、网页空间、绵阳服务器托管、企业网站设计、和静网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

具体实现:

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);

分享标题:(WCF)利用WCF实现两个Process之间的通讯。-创新互联
当前URL:https://www.cdcxhl.com/article48/csoihp.html

成都网站建设公司_创新互联,为您提供外贸网站建设响应式网站建站公司动态网站标签优化App开发

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

h5响应式网站建设