简体   繁体   English

为什么需要wcf双工?

[英]why is wcf duplex required?

WCF duplex performs a callback after a method has run on the server that then runs code on the client. 在服务器上运行方法之后,WCF双工执行回调,然后在客户端上运行代码。

If i want to execute a method on the client from the server at the push of a button on the server then i don't think WCF duplex is appropriate. 如果我想通过按服务器上的按钮从服务器上的客户端上执行一种方法,那么我认为WCF双工不合适。

Why would i not just create a client and a server at each end of my 2 applications? 为什么我不只是在两个应用程序的每个末端都创建一个客户端和一个服务器?

I was one of the people that commented on your previous question so I probably owe you an answer here :o) 我是对您以前的问题发表评论的人之一,所以我可能在这里欠您一个答案:o)

You have posted rather a lot of code and I have not looked at it in detail. 您已经发布了很多代码,而我没有详细介绍它。 However, in general terms, there is a reason for using wsDualHttpBinding and duplex contracts in general instead of more of a peer-to-peer approach where you have services on both sides, as follows: 但是,总的来说,有一个原因通常使用wsDualHttpBinding和双工协定,而不是更多地使用对等方法来实现双方的服务,原因如下:

The duplex approach is appropriate where you have a clearly defined server that is running permanently. 如果您有明确定义的且永久运行的服务器,则双工方法是合适的。 This provides the hub of the interaction. 这提供了交互的枢纽 The idea is that clients are in some way more transient than the server. 这个想法是,客户端在某种程度上比服务器更具瞬态性。 The clients can start up and shut down or move location and the server does not need to be aware of them in advance. 客户端可以启动,关闭或移动位置,服务器不需要事先知道它们。 When the client starts up, it is pre-configured to know where the server is, so it can "register" itself with the server. 客户端启动时,将对其进行预配置以了解服务器的位置,以便它可以向服务器“注册”自身。

In contrast, the server does not need to be preconfigured to know where the clients are. 相反,不需要预先配置服务器即可知道客户端的位置。 It starts up and can run independently of any clients. 它会启动,并且可以独立于任何客户端运行。 It just accepts "registrations" from all clients that have valid credentials whenever they come online, and can continue to run after the client goes offline. 它仅接受具有有效凭据的所有客户端上线的所有“注册”,并且可以在客户端脱机后继续运行。 Also, if the client moves, it just re-registers itself with the server at its new location. 同样,如果客户端移动,它只是在服务器的新位置重新注册自己。

So the server is in some sense a more "important" part of the system. 因此,从某种意义上说,服务器是系统中更“重要”的部分。 No client can participate in the communication without the server, but the server can operate independently of any client. 没有服务器,没有客户端可以参与通信,但是服务器可以独立于任何客户端运行。

To do this with WCF duplex service, you have to do some extra work yourself to implement the publish/subscribe behaviour. 要使用WCF双工服务来执行此操作,您必须自己做一些额外的工作才能实现发布/订阅行为。 Fortunately, the MSFT Patterns and Practises team have provided some guidance on how to do it 幸运的是,MSFT模式和实践团队已经提供了一些指导,以帮助您实现目标。

http://msdn.microsoft.com/en-us/library/ms752254.aspx http://msdn.microsoft.com/en-us/library/ms752254.aspx

This is fundamentally different from a genuine peer-to-peer approach where there is no well-defined hub (ie server) for the network and each node can come and go without affecting the overall functioning of the network. 这与真正的点对点方法根本不同,在真正的点对点方法中,网络没有明确定义的集线器(即服务器),每个节点可以来去去而不会影响网络的整体功能。

WCF Duplex is used when you have a Publish/Subscribe setting (also known as the Observer Pattern ). 当您具有“发布/订阅”设置(也称为“ 观察者模式” )时,将使用WCF Duplex。 Let's say you have a service that subscribes for notifications of some sort (eg new email). 假设您有一项订阅某种通知(例如新电子邮件)的服务。 Normally, you would need to check periodically for updates. 通常,您需要定期检查更新。 Using WCF Duplex, the subscriber can be notified automatically by the publisher when there are updates. 使用WCF Duplex,发布者可以在更新时自动通知订阅者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM