Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6036425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:55:21+00:00 2026-05-23T05:55:21+00:00

I’m trying to figure out why when you have multiple callback clients connected using

  • 0

I’m trying to figure out why when you have multiple callback clients connected using the well-known publish-subscribe pattern when one faults or when one disconnects without unsubscribing all the clients states are set to Closed then Faulted.

   [ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(ICallback))]
   public interface IPubSubService
   {
      [OperationContract(IsOneWay = false, IsInitiating = true)]
      void Subscribe();

      [OperationContract(IsOneWay = false, IsInitiating = true)]
      void UnSubscribe();

      [OperationContract(IsOneWay = false)]
      void BroadcastMessage(string message);
   }


   [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
   public class PubSubService : IPubSubService
   {
      private ICallback _callbackClient;
      public static event Action<string> _action;

      public void Subscribe()
      {
         _callbackClient = OperationContext.Current.GetCallbackChannel<ICallback>();
         _action += ActionInvoked;
      }

      public void UnSubscribe()
      {
         _action -= ActionInvoked;
      }

      public void BroadcastMessage(string message)
      {
         _action.Invoke(message);
      }

      public void ActionInvoked(string message)
      {
         _callbackClient.SendMessage(message);
      }
   }

   public interface ICallback
   {
      [OperationContract(IsOneWay = true)]
      void SendMessage(string message);
   }


// The Publisher that doesn't subscribe only sends the message
[CallbackBehaviorAttribute(UseSynchronizationContext = false)]
   public partial class Form1 : Form, ICallback
   {
      public Form1()
      {
         InitializeComponent();
      }

      private ServiceClient _proxy;

      private void button1_Click(object sender, EventArgs e)
      {
         try
         {
            _proxy = new ServiceClient(new InstanceContext(this));
            _proxy.BroadcastMessage(textBox1.Text);
         }
         catch (Exception exception)
         {
            Console.WriteLine(exception);
         }
      }


      public void SendMessage(string message)
      {

      }
   }

   public static class ControlExtensions
   {
      public static void Invoke(this Control Control, Action Action)
      {
         Control.Invoke(Action);
      }
   }

   public class ServiceClient : DuplexClientBase<IPubSubService>, IPubSubService
   {
      public ServiceClient(InstanceContext callbackInstance)
         : base(callbackInstance)
      { }

      public void Subscribe()
      {
         Channel.Subscribe();
      }

      public void UnSubscribe()
      {
         Channel.UnSubscribe();
      }

      public void BroadcastMessage(string message)
      {
         Channel.BroadcastMessage(message);
      }
   }

// The Subscriber
[CallbackBehaviorAttribute(UseSynchronizationContext = false)]
   public partial class Form1 : Form, ICallback
   {
      public Form1()
      {
         InitializeComponent();
      }

      private ServiceClient _proxy;

      private void button1_Click(object sender, EventArgs e)
      {
         _proxy = new ServiceClient(new InstanceContext(this));
         _proxy.Subscribe();
         this.Invoke(() => textBox1.AppendText("Subscribed..."));

      }

      public void SendMessage(string message)
      {
         this.Invoke(() => textBox1.AppendText(message + "\r\n"));
      }

      private void button2_Click(object sender, EventArgs e)
      {
         if (_proxy != null && _proxy.State == CommunicationState.Opened)
         {
            _proxy.UnSubscribe();
         }
      }

      private void button3_Click(object sender, EventArgs e)
      {
         Thread.Sleep(new TimeSpan(0, 1, 0));
      }
   }

   public static class ControlExtensions
   {
      public static void Invoke(this Control Control, Action Action)
      {
         Control.Invoke(Action);
      }
   }

   public class ServiceClient : DuplexClientBase<IPubSubService>, IPubSubService
   {
      public ServiceClient(InstanceContext callbackInstance) : base(callbackInstance)
      { }

      public void Subscribe()
      {
         Channel.Subscribe();
      }

      public void UnSubscribe()
      {
         Channel.UnSubscribe();
      }

      public void BroadcastMessage(string message)
      {
         Channel.BroadcastMessage(message);
      }
   }


// config for both clients publisher and subscriber

<configuration>
  <system.windows.forms jitDebugging="true" />
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="netTCPBinding">
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="true"/>
          <security mode="None">
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint
        address="net.tcp://localhost:8008/PubSubService"
        binding="netTcpBinding"
        bindingConfiguration="netTCPBinding"
        contract="ServiceLibrary.IPubSubService"
        name="netTCPBinding">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
  <startup>
  </startup>
</configuration>

// config for Service

<?xml version="1.0"?>
<configuration>  
  <system.serviceModel>
    <services>
      <service name="ServiceLibrary.PubSubService">
        <endpoint address="net.tcp://localhost:8008/PubSubService"
                  binding="netTcpBinding"
                  bindingConfiguration="netTCPBinding"
                  contract="ServiceLibrary.IPubSubService"/>
      </service>
    </services>
    <bindings>
      <netTcpBinding>
        <binding name="netTCPBinding" closeTimeout="00:00:10" openTimeout="00:00:10" receiveTimeout="00:00:10" sendTimeout="00:00:10" transactionFlow="false" transferMode="Buffered" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="1000" maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="true"/>
          <security mode="None">
          </security>
        </binding>
      </netTcpBinding>      
    </bindings>
  </system.serviceModel>  
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:55:22+00:00Added an answer on May 23, 2026 at 5:55 am

    Isn’t it simply a case of the disconnected client causes the event raising to throw an exception when processing its invocation list and therefore all remaining clients don;t get invoked – you could process the invocation list manually something like this

            List<Action<string>> targets = _action.GetInvocationList().Cast<Action<string>>().ToList();
    
            foreach(var target in targets)
            {
               try
               {
                   target(message);
               }
               catch(CommunicationException)
               {
                   _action -= target;
               }
            }
    

    Edit (After looking at the code)

    You are using NetTcpBinding which is inherently sessionful. That session will be torn down (disconnected) in one of two situations – when the client closes their proxy or when the services receiveTimeout is exceeded between requests.

    In your PubSubService host you had the receive timeout (which affects the subscribers sessions) set to 5 seconds, the same as the sendTimeout (which affects the time you’ll wait before deciding the subscriber is dead when you are broadcasting). So by the time you realise the subscriber is dead, all of the other subscribers have timed out their sessions

    Increase your receiveTimeout in the PubSubService host to the amount of time you want the subscriptions to be valid and it will work fine

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.