Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After the first receiver exits, its channel is still saved in the receiverClients collection in the service, so the next time a transmit occurs, the server will attempt to callback to a non-existent client. You must remove the receiver from the collection when it ends, perhaps with an unsubscribe contract operation. There are a number of ways to implement this. Here is one example. (These are the changes, only - please let me know if you would like the entire project.)</p> <p>In IContactManagerUserService.cs:</p> <pre><code>// receivers must identify themselves [OperationContract(IsOneWay = true)] void SubscribeAsReceiver(string receiverID); // new operation [OperationContract(IsOneWay = true)] void UnSubscribeAsReceiver(string receiverID); </code></pre> <p>In ContactManagerUserService.cs</p> <pre><code>// replace synchronized collection with thread-safe dictionary using System.Collections.Concurrent; ConcurrentDictionary&lt;string, IContactManagerCallBackService&gt; receiverClients; public ContactManagerUserService() { receiverClients = new ConcurrentDictionary&lt;string, IContactManagerCallBackService&gt;(); } public void SubscribeAsReceiver(string receiverID) { IContactManagerCallBackService client = OperationContext.Current.GetCallbackChannel&lt;IContactManagerCallBackService&gt;(); receiverClients.TryAdd(receiverID, client); } public void UnSubscribeAsReceiver(string receiverID) { IContactManagerCallBackService client; receiverClients.TryRemove(receiverID, out client); } public void TransmitUserData(UserInfo info) { foreach (IContactManagerCallBackService receiverClient in receiverClients.Values) { receiverClient.PublishUserData(info); } } </code></pre> <p>In ReceiverClient.Program.cs (don't forget to update ServiceReferences since the contract has changed):</p> <pre><code>// one way to uniquely identify this receiver string rcvID = Guid.NewGuid().ToString(); // .... // receivingClient.SubscribeAsReceiver(rcvID); // .... // Console.ReadLine(); // Important - this line must be executed, or service will again throw error. // So when debugging, don't just close window, press enter to execute this line. // In more robust setting, this would probably go in finally{} block, or in Dispose() receivingClient.UnSubscribeAsReceiver(rcvID); </code></pre> <p><strong>Debugging Tip</strong> You may want to have a version of the service you can run locally, so you can step into it and debug it. Also, I have found logging messages to the service log to be very helpful when you can't run the service locally.</p> <p>You can search WCF Publisher/Subscriber for more info. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload