之间使用WCF 2 WinForm应用程序通信? [英] Communication between two winform application using WCF?

查看:118
本文介绍了之间使用WCF 2 WinForm应用程序通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同的WinForm应用程序,程序App1和APP2。 APP1称APP2的exe文件(使用DOS命令窗口),并发送消息到开始APP2。该APP2开始执行,一旦它完成它的任务,它发回的消息,APP1的执行是成功的。我怎样才能acheieve使用WCF此功能。前面相同的code是写在FoxPro和该FINC使用的内存管理来实现的。

I have two different winform application, App1 and app2. App1 calls the exe of app2 (using DOS command window) and sends a message to start the app2. The app2 starts executing and once it finishes its task it sends back the message to app1 that the execution was successful. How can I acheieve this functionality using WCF. earlier the same code was written in foxpro and this finc was achieved using memory management.

推荐答案

基本上是:

在一边实例化一个服务器

on one side instanciate a "server"

UIIServiceHost = new ServiceHost(typeof(UIInterop));
UIIServiceHost.Open();

在这里UIInterop是一个类implementaing IUIInterop这是一个服务合同

where UIInterop is a class implementaing IUIInterop that is a Service Contract

using System.ServiceModel;

[ServiceContract]
public interface IUIInterop {
    [OperationContract]
    void SetControlValue (UIControl c);
}

[DataContract]
public class UIControl {        
    [DataMember]
    public String Name { get; set; }

    [DataMember]
    public String Value { get; set; }
}

生成代理类=> UIInteropClient

Generate a proxy class => UIInteropClient

在另一边使用代理类实现一个客户端

on the other side implement a client using the proxy class

using ( UIInteropClient proxy = new UIInteropClient("nameDependingOfAppConfig") ) {
    proxy.SetControlValue(new UIControl {});
}

=====编辑=====

===== EDIT =====

的类和接口名称只表示我缺乏想象力

the name of classes and interfaces only reflect my lack of imagination

这篇关于之间使用WCF 2 WinForm应用程序通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆