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 6598065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:17:30+00:00 2026-05-25T18:17:30+00:00

I implemented my own code of Publish/subscribe pattern implementation with WCF with WSDualHttpBinding, but

  • 0

I implemented my own code of Publish/subscribe pattern implementation with WCF with WSDualHttpBinding, but i’ve a little problem with timeouts that i explain later, for now let me show what i’m doing:

public interface IEventSubscriber
{
    [OperationContract]
    void NotifyEvent(EventNotification notification);
    [OperationContract]
    void NotifyServiceDisconnecting();
}

[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IEventSubscriber))]
public interface IEventPublisherService
{
    [OperationContract(IsOneWay = false, IsInitiating = true)]
    void Subscribe(string culture);
    [OperationContract(IsOneWay = false, IsInitiating = false, IsTerminating = true)]
    void Unsubscribe();
}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
internal class EventPublisherServiceImpl : IEventPublisherService
{
    ServiceHost host;
    public bool StartService()
    {
        bool ret = false;
        try
        {
            Uri baseAddress = new Uri(ConfigurationManager.AppSettings[GlobalConstants.CfgKeyConfigEventPublishserServiceBaseAddress].ToString());
            EventHelper.AddEvent(string.Format("Event Publisher Service on: {0}", baseAddress.ToString()));

            host = new ServiceHost(this, baseAddress);

            // duplex session enable http binding
            WSDualHttpBinding httpBinding = new WSDualHttpBinding(WSDualHttpSecurityMode.None);
            httpBinding.ReceiveTimeout = TimeSpan.FromMinutes(10);
            httpBinding.ReliableSession = new ReliableSession();
            httpBinding.ReliableSession.Ordered = true;
            httpBinding.ReliableSession.InactivityTimeout = TimeSpan.FromMinutes(10);
            host.AddServiceEndpoint(typeof(IEventPublisherService), httpBinding, baseAddress);

            // Enable metadata publishing.
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            host.Description.Behaviors.Add(smb);

            // Open the ServiceHost to start listening for messages.
            host.Open();
            ret = true;
        }
        catch (Exception e)
        {
            EventHelper.AddException(e.Message);
        }

        return ret;
    }
 ...

}

now in my implementation class i have a list of subscribers that are stored in memory, when a new notification arrived the following code is performed for each subscriber:

 ...
    /// <summary>
    /// List of active subscribers
    /// </summary>
    private static Dictionary<IEventSubscriber, string> subscribers = new Dictionary<IEventSubscriber, string>();

 ...

that i use it like this:

    internal void Subscribe(string culture)
    {
        lock (subscribers)
        {
            // Get callback contract as specified on the service definition
            IEventSubscriber callback = OperationContext.Current.GetCallbackChannel<IEventSubscriber>();

            // Add subscriber to the list of active subscribers
            if (!subscribers.ContainsKey(callback))
            {
                subscribers.Add(callback, culture);
            }
        }
    }

 ...

    private void OnNotificationEvent(NormalEvent notification)
    {
        lock (subscribers)
        {
            List<IEventSubscriber> listToRemove = new List<IEventSubscriber>();
            //  Method signature: Parallel.ForEach(IEnumerable<TSource> source, Action<TSource> body)
            Parallel.ForEach(subscribers, kvp =>
            {
                try
                {
                    kvp.Key.NotifyEvent(new EventNotification(notification, kvp.Value));
                }
                catch (Exception ex)
                {
                    EventHelper.AddException(string.Format("Error notifying event notification to client: {0} - removing this one", ex.Message));
                    listToRemove.Add(kvp.Key);
                }

            } //close lambda expression
            ); //close method invocation

            Parallel.ForEach(listToRemove, subs =>
            {
                try
                {
                    subs.NotifyServiceDisconnecting();
                }
                catch (Exception ex) {
                    EventHelper.AddException(string.Format("Failed to notify client that is to be removed: {0}", 
                        ex.Message));
                }
                subscribers.Remove(subs);
            }
            );
        }
    }

What is the problem with this, when timeouts are achieved (note that i set 10 minutes for ReceiveTimeout and inactive timeout) the subscribers that are in the list go to fault state, and the following exception is catched in the OnNotificationEvent

*The operation ‘NotifyEvent’ could not be completed because the sessionful channel timed out waiting to receive a message. To increase the timeout, either set the receiveTimeout property on the binding in your configuration file, or set the ReceiveTimeout property on the Binding directly. *

Ok i can increase the timeout value, but if i do this it will happen some time, eventually.

My question are: i’m doing something wrong when trying to implement this pattern? or exists any other way of implementing this pattern a better way that avoid this problem? or exist any way of reconnecting the faulted callback channel (for what i’m reading it’s not possible, but due to that i can’t notify the client that is connection was lost, letting the client blind not knowing that the communication ended!? or is a way to give knowledge that he lost communication with the publisher!?)

Of course solution like ping messages are out of date 🙂 but ok, if nothing better appears look like i’ve to implement something like that…

Thanks

  • 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-25T18:17:31+00:00Added an answer on May 25, 2026 at 6:17 pm

    For now the solution was to change the timeouts to have a infinite value:

                // duplex session enable http binding
                WSDualHttpBinding httpBinding = new WSDualHttpBinding(WSDualHttpSecurityMode.None);
                httpBinding.ReceiveTimeout = TimeSpan.MaxValue;
                httpBinding.ReliableSession = new ReliableSession();
                httpBinding.ReliableSession.Ordered = true;
                httpBinding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement my own GenericIdentity implementation but keep receiving the following error
The code I'm working with has its own smart pointer implementation which does simple
I have implemented my own class that inherits from the SettingsProvider class. If the
I have this UIView that I subclassed and implemented my own drawRect method. When
I have implemented a cryptography algorithm using my own code using C#.net , i
Just for fun, I implemented my own stack, but, without using a linked list,
I have implemented my own editor and added a code completion functionality to it.
So, I've successfully implemented my own MembershipProvider and that's working exactly as I intended
I have this code, that goes through steps, aquired from a webservice. I implemented
Hey, right now I have implemented my own listener pattern. I will send an

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.