简体   繁体   English

WCF服务器调用客户端方法

[英]WCF Server call Client Method

I have a server which is connected to a few clients (with WCF and netTcpBinding). 我有一台连接到几个客户端(带有WCF和netTcpBinding)的服务器。

At an undefinite point in time I want the server to call the method of a specific client (and have a string as a parameter). 在一个不确定的时间点,我希望服务器调用特定客户端的方法(并使用字符串作为参数)。 The server only knows which client when he wants to call it. 服务器仅在要调用哪个客户端时才知道。

Basically one client has to wait for a server to send him a message (but in the meantime, other clients call the server as well) and the server needs to know exactly which client he needs to call. 基本上,一个客户端必须等待服务器向他发送消息(但与此同时,其他客户端也会调用该服务器),并且服务器需要确切知道他需要呼叫哪个客户端。 (The client has an attribute and the server wants to call the method on the client with a specific attribute) (客户端具有属性,服务器希望使用特定属性在客户端上调用方法)

Is there a way to do this? 有没有办法做到这一点?

EDIT: I thought of a possibility, but I think there is a better way.. for the moment the client will call a method with parameters specifying the ip and port of the client. 编辑:我想到了一种可能性,但我认为有一种更好的方法..目前客户端将调用带有指定客户端IP和端口的参数的方法。 The server will add it to a list and when the server wants to call the client, he searches the list for the attribute and connects to the client (on the client a service is hosted as long as the client is waiting) 服务器会将其添加到列表中,并且当服务器要调用客户端时,他会在列表中搜索属性并连接到客户端(在客户端上,只要客户端在等待,就托管服务)

WCF already has support for this built in. You need to create a duplex contract . WCF已经内置了对此功能的支持。您需要创建一个双工合同 The server can then call any connected clients whenever it wants. 然后,服务器可以在需要时调用任何已连接的客户端。

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

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