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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:08:51+00:00 2026-05-23T01:08:51+00:00

I have a simple WCF service serving up notifications to and from an app.

  • 0

I have a simple WCF service serving up notifications to and from an app.
the service holds a static list of subscribers, and before it tries to send a message to any of them, it checks …

((ICommunicationObject)callback).State == CommunicationState.Opened

unfortunately if the app consuming the WCF service falls over – thus not unsubscribing itself from the WCF service, the service will hang around and eventually timeout. far from ideal.
in an attempt to sort this I added

OperationContext.Current.Channel.Faulted += new EventHandler(Channel_Faulted);

in the subscription method, but it is never hit.
is there a reliable way to determine whether or not the callback channel is in fact open?
or maybe to asynchronously send the messages so that if a subscriber appears in the list but is actually dead, the service wont wait around like a geek being stood up on a date? 🙂

any help most happily received

thanks

nat

full code for service below…

private static readonly List<INotificationCallback> subscribers = new List<INotificationCallback>();

    public void AddMessage(string SendingUser, string message, List<string> users, MessageType messageType, Guid? CaseID)
    {

        subscribers.ForEach(delegate(INotificationCallback callback)
        {

            if (((ICommunicationObject)callback).State == CommunicationState.Opened)
            {
                callback.OnMessageAdded(SendingUser, message, users, messageType, DateTime.Now, CaseID);
            }
            else
            {
                RemoveSubscriber(callback);
            }
        });
    }

    public bool Subscribe()
    {
        try
        {
            INotificationCallback callback = OperationContext.Current.GetCallbackChannel<INotificationCallback>();
            OperationContext.Current.Channel.Faulted += new EventHandler(Channel_Faulted);
            OperationContext.Current.Channel.Closed += new EventHandler(Channel_Closed);
            if (!subscribers.Contains(callback))
                subscribers.Add(callback);
            return true;
        }
        catch
        {
            return false;
        }
    }

    private void RemoveSubscriber(INotificationCallback callback)
    {
        if (subscribers.Contains(callback))
            subscribers.Remove(callback);
    }

    void Channel_Closed(object sender, EventArgs e)
    {
        INotificationCallback machine = sender as INotificationCallback;
        RemoveSubscriber(machine);
    }

    void Channel_Faulted(object sender, EventArgs e)
    {
        INotificationCallback machine = sender as INotificationCallback;
        RemoveSubscriber(machine);
    }

    public bool Unsubscribe()
    {
        try
        {
            INotificationCallback callback = OperationContext.Current.GetCallbackChannel<INotificationCallback>();
            RemoveSubscriber(callback);
            return true;
        }
        catch
        {
            return false;
        }
    }
  • 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-23T01:08:51+00:00Added an answer on May 23, 2026 at 1:08 am

    ended up ditching the HttpBinding and switched to NetTcpBinding which raises the the fault event immediately.

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

Sidebar

Related Questions

I have a simple WCF service that I call server side from code behind
I have a simple WCF service that will analyse a raw text extracted from
I have a simple console app that calls a WCF service over net.tcp and
I have a simple WCF service: public Order[] GetOrdersByStatus(int statusid) { OrderService os =
I have created a simple wcf service which used the WCF Service Library template.
I have a simple WCF Service that needs to handle large datastreams, so I
I have a simple WCF Web service. It's hosted on IIS under the default
I have written a simple WCF service that accepts and stores messages. It works
I have a very simple WCF service that I would like to expose publicly.
I have a quite simple WCF service method which returns an IQueryable, just for

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.