积极答复者
请教一个解决方案

问题
-
同一台机器不同进程之间的通讯。
用NetNamedPipe。
希望能做到各个client之间能够相互发现,能够相互通信。不知道用WCF怎么解决。
Discovery吗?
- 已编辑 geminiyellow 2012年5月7日 23:49
答案
-
如果你在WinForm下面运行的话,因为应用程序都运行在同一个线程上(UI线程), 所有服务请求的处理都在一个线程上安顺序执行,可能会出现程序没有响应,一直等待。像是这种情况你须要新建一个线程来运行服务或使用[ServiceBehavior(UseSynchronizationContext = false)]在服务上。详细你可以参考:http://stackoverflow.com/questions/4743050/any-recommendations-to-host-a-wcf-service
Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
- 已标记为答案 geminiyellow 2012年5月13日 23:45
全部回复
-
是的 如果你想 各个客户端可以相互发现 确实 WCF4.0提供了 服务发现 机制,2种模式,主动Ad-hoc和 托管模式。
你可以看看 我的文章
WCF4.0新特性体验(10):服务发现WS-Discovery之简单的Ad hoc Service Discovery
WCF4.0新特性体验(12):服务发现WS-Discovery之Managed Service Discovery
Frank Xu Lei--谦卑若愚,好学若饥
[老徐的网站]:http://www.frankxulei.com/[老徐的博客]:http://54peixun.com/Author/frankxulei
微软WCF中文技术论坛
微软WCF英文技术论坛
Windows Azure中文技术论坛 -
谢谢老徐。顺便说一句,买了第三版。
因为是新手,所以有些地方理解不通。
我写了这样一个尝试代码‘
private void ActionInitService() { try { _host = new ServiceHost(this, new Uri(ADDRESS_PIPE_BASE)); var binding = new NetNamedPipeBinding(); _host.AddServiceEndpoint((typeof (IClientService)), binding, Address.ToString()); // ** DISCOVERY ** // _host.Description.Behaviors.Add(new ServiceDiscoveryBehavior()); _host.AddServiceEndpoint(new DiscoveryEndpoint(binding, new EndpointAddress(ADDRESS_PIPE_BASE))); } catch (Exception ex) { Debug.WriteLine("exp: " + ex); } }
public ObservableCollection<string> FindRunningClient() { var endpoints = new ObservableCollection<string>(); try { var binding = new NetNamedPipeBinding(); var address = new EndpointAddress(ADDRESS_PIPE_BASE); var discoveryClient = new DiscoveryClient(new DiscoveryEndpoint(binding, address)); FindResponse rk2Clients = discoveryClient.Find(new FindCriteria(typeof(IClientService))); discoveryClient.Close(); if (rk2Clients.Endpoints.Count != 0) { foreach (EndpointDiscoveryMetadata endpoint in rk2Clients.Endpoints) { endpoints.Add(endpoint.Address.ToString()); } } return endpoints; } catch (Exception e) { return endpoints; } }
但是每次跑的时候只能找到第一个启动的Service。这是什么原因呢?用UDP是可以发现。但是不太想用UDP的发现。
老徐还想问你一个问题,如果用托管方式来进行发现。当Proxy关闭了再启动。这时候应该怎么做?
野老
- 已编辑 geminiyellow 2012年5月8日 4:29
-
Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
-
Peter你好,这个链接我也看到了。
我有一个问题,如果
我在同一个exe中,
启动了ServiceManager,
又启动了ServiceChild。
用ServiceChild去链接ServiceManager,把自己在ServiceManager中注册一下。
是会出异常的。
请问是不是一个exe中的两个Service一定不能交互?
野老
- 已编辑 geminiyellow 2012年5月9日 4:21
-
如果你在WinForm下面运行的话,因为应用程序都运行在同一个线程上(UI线程), 所有服务请求的处理都在一个线程上安顺序执行,可能会出现程序没有响应,一直等待。像是这种情况你须要新建一个线程来运行服务或使用[ServiceBehavior(UseSynchronizationContext = false)]在服务上。详细你可以参考:http://stackoverflow.com/questions/4743050/any-recommendations-to-host-a-wcf-service
Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
- 已标记为答案 geminiyellow 2012年5月13日 23:45