简体   繁体   中英

WCF Server call Client Method

I have a server which is connected to a few clients (with WCF and 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. 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 . The server can then call any connected clients whenever it wants.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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