user207809
user207809

Reputation: 61

How to use a duplex wcf service to distribute messages to all clients?

I am building a simple duplex wcf service. In this service clients send messages to the server and the server distributes the message to all connected clients. However, despite the fact that I defined the ServiceBehavior attribute as [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)], only the client who sent the message receives it back from the server, while the other clients do not. I verified that there is just one instance of the server running. What did I do wrong? I looked at other similar questions on the web, and they all say that I should define InstanceContextMode = InstanceContextMode.Single, which I already did.

Upvotes: 0

Views: 2333

Answers (1)

Kalidoss M
Kalidoss M

Reputation: 556

Do you have a callback Contract. So that server will reply back to client. Check the below tutorial for Implementing Callback Contract Click here

Also check the below Project Event Notification server. This project is doing similar things what you want.

CodeProject Link

Feel free to ask me if you need any more clarification

You need to maintain the clistList as shown in the code snippet.

List<IMessageServiceCallback> clientList = new List<IMessageServiceCallback>();
public void Register()
{ 
    IMessageServiceCallback callback = OperationContext.Current.GetCallbackChannel<IMessageServiceCallback>(); 
    clientList.add(callback);
}

When you want to broadcast this message. You can iterate through the list and call the callback function to send message to clients.

Upvotes: 1

Related Questions