views:

132

answers:

2

What does OperationContext.Current.GetCallbackChannel actually do? How does it identify each and every client?

I'm facing a problem in my WCF service. If more than two users get connected to the service all the "interesting Changes" i'm sending from service to the clients are going to the second joined user.

For ex, If A, B, C, D joins the service if i send the changes to C and D through callback it is going to B.

Any ideas?

Details:

Client : ASP.NET web app

Binding: netTCPBinding

Update1

Okie, i've found the cause of the issue. I've hosted the asp.net client in IIS. For example the URL of the client is http://url1. If i open multiple instances of the page in different machine and join the service the callback channel is always pointing to the first instance of the page (i open the site from different machines). But if i host the asp.net client under different sites in IIS the callback channels are unique. Any thoughts on that?

A: 

You have to configurate your service to create separated thread for each session. Take a look to http://msdn.microsoft.com/en-us/library/cc681240.aspx

Nagg
Yes, i know that. I've configured the session mode and instance context and other configurations required for creating a duplex contract with callback. All my question is how it actually creates a channel with the client?
NLV
+2  A: 

When the service receives a call, OperationContext.Current.GetCallbackChannel returns a channel to just that caller. It does not return a channel that broadcasts to all of the clients.

From your question, it's possible that you are only storing the callback that was retrieved in the last call. You actually have to store a list, containing each unique callback instance that has been retrieved. Every time a method is called, you add the callback instance to this list. When you want to broadcast, you have to iterate through each item in the list and make the necessary call.

If your service uses the Singleton instance mode, the implementation object can store a list of callback instances as a data member. If your sevice uses the Client or SingleCall instance mode, then you could have a global object that contains the list of callback instances.

Andrew Shepherd
Yes. This is how i'm exactly doing it. I'm using [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)] for my service. But i'm still getting the same problem. Now i've created a dictionary to store the callback channels. Still all callback channels for the users joined after the second user (from third user) is always pointing to the second user. I'm following this great article - http://www.codeproject.com/KB/WCF/WCFWPFChat.aspx by Sacha Barber.
NLV
Is that "OperationContext.Current.GetCallbackChannel" is based on the proxy object i use to call the service from the client?
NLV
Updated my post. Please check it.
NLV