使用WCF进行双向通讯 [英] Two-way Communication Using WCF

查看:57
本文介绍了使用WCF进行双向通讯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计使用Windows Communication Foundation实现的客户端-服务器体系结构.在一种使用情况下,服务器需要请求状态的客户端,这意味着它需要在上调用 SendStatus()方法>客户,并询问其状态.我只是想知道是否可以使用WCF来实现此用例,而无需在客户端上创建独立的服务.我试图避免使用套接字,因为客户端是后台服务,并且基本上始终连接到服务器.我知道WCF最终会使用套接字进行通信,但是我专门尝试使用WCF,因为这更像是一种概念证明.

I'm designing a client-server architecture which is implemented using Windows Communication Foundation. In one of the use cases, the server needs to request the status of the client(s), which means it needs to call the SendStatus() method on the client and ask for its status. I was just wondering if this use case can be implemented using WCF, without creating a standalone service on the client side. I'm trying to avoid sockets because the client is a background service and is essentially always connected to the server. I understand that WCF eventually uses sockets for communication, but I'm specifically trying to use WCF since this is more like a proof of concept.

我想到的一种解决方法是,客户端可以在服务器上调用 SendClientStatus()方法,并每5秒钟左右发送一次其状态.但是话又说回来,这似乎不是一个好方法.任何帮助将不胜感激.

A workaround I thought of was that the client could call the SendClientStatus() method on the server and send its status every 5 seconds or so. But then again this doesn't seem like a good approach. Any help would be appreciated.

推荐答案

在WCF中,您或多或少有两个选择.

In the world of WCF, you have more or less two options.

A)具有双重Http绑定的双重服务

B)一种无返回值的轮询方案-本质上就是您所描述的.如您正确指出的那样,幼稚的实现不是那么好,但是有一些优化.由于您不需要从SendClientStatus返回的任何内容(正确吗?),因此可以通过仅在存在更新时发送更新(例如,更新)来优化通信.只要客户端的状态保持不变,什么都不会发送到服务器.根据客户端状态更改的频率,这可以大大减少流量.除非确实需要,否则双工服务会提供一些您想要避免的额外配置.

B) A no-return-value polling scheme - this is essentially what you described. The naive implementation, as you correctly note, is not that great, but there are optimizations. Since you do not need anything returned from SendClientStatus (correct?) , you can optimize the communication by only sending an update when there is one - e.g. as long as the status of the client remains the same, nothing is sent to the server. Depending on the frequency with which client status changes, this can greatly reduce the traffic. Duplex services present some extra configuration you want to avoid unless you really need them.

这篇关于使用WCF进行双向通讯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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