metalcam
metalcam

Reputation: 402

How to get only one instance when calling GetCallbackChannel()?

I'm having a little problem with my WCF service.
Actually, a user can subscribe to a "publishing" service.

I'm simply doing a OperationContext.Current.GetCallbackChannel<IPublishing>();
Then I add the the returned object into a List (a kind of List<IPublishing>)

As I want my clients to be notified when I publish a message, I simply call the callback of all the subscribed users.

It works great, but a user can subscribe twice and I don't want to.
It's why I do a if (!theList.Contains(theCallbackChannelReturned)) in order to verify this constraint...

The fact here is that everytime I create the callbackchannel, it seems that he create another new instance of IPublishing, even on the same client...

I don't know how to do to accomplish this... I figured out that OperationContext.Current.InstanceContext returns still the same Hashcode but GetCallbackChannel doesn't...

Thank you !

Upvotes: 0

Views: 355

Answers (1)

tom redfern
tom redfern

Reputation: 31780

In your client callback implementation you should do the following:

[CallbackBehavior(
    ConcurrencyMode = ConcurrencyMode.Reentrant, 
    UseSynchronizationContext = false)]
public partial class ServiceClient : IMyService_Callback 
{ .... }

Upvotes: 1

Related Questions