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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:22:40+00:00 2026-06-16T01:22:40+00:00

I have a Windows service hosting a WCF service that broadcasts information to several

  • 0

I have a Windows service hosting a WCF service that broadcasts information to several clients. I would like to gracefully handle a service shutdown from the client, i.e. detect that the service has dissapeared or wants to close, pop up a message and close the app. Currently if I shut down the service at the close line I get the following.

“The ServiceHost close operation timed out after 00:00:09.9910000. This could be because a client failed to close a sessionful channel within the required time. “

QUESTION: How do I detect the close request and shut the client down?

After the service closes on the client I get “Socket Exception ocurred An existing connection was forcibly closed by the remote host”

here is the close code.

If Not (_LivePricingHost Is Nothing) Then
    _LivePricingHost.Close()
    _LivePricingHost = Nothing
End If

Here is the class I use to set up the duplex sessions, I have removed the boilerplate dispose code and the events I am raising up to the client.

Imports System.ServiceModel

Public Class NotificationCallback
    ' Implements LivePricingService.IMessageCallback
    Implements IDisposable

    Private _ns As LivePricingService.MessageClient

    Public Sub New()
        Dim context = New InstanceContext(Me)

        _ns = New LivePricingService.MessageClient(context)
        _ns.SubscribeForBroadcast()
        '    _ns.AddMessage("PING")
    End Sub

 #End Region

End Class

  • 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-06-16T01:22:41+00:00Added an answer on June 16, 2026 at 1:22 am

    The solution is to add an “Unsubscribe” method to the callback interface. Then the client can unsubscribe.
    So when the service is stopping it asks the clients to disconnect.

       Protected Overrides Sub OnStop()
            pollTimer.Stop()
            _LivePricingWCFService.UnsubscribeAll()
            If Not (_LivePricingHost Is Nothing) Then
                _LivePricingHost.Close()
                _LivePricingHost = Nothing
            End If
        End Sub
    

    On the WCF service

       Public Sub UnsubscribeAll()
            Try
                RemoveClosedSubscribers()
    
                For Each callback As IMessageCallback In _subscribers
                    If DirectCast(callback, ICommunicationObject).State = CommunicationState.Opened Then
                        callback.ShutDown() 'request that the client disconnect
                        _subscribers.Remove(callback)
                    End If
                Next
            Catch ex As Exception
                Logging.Logger.LogMessage(ex:=)
            End Try
        End Sub
    

    and on the client

    Public Sub ShutDown() Implements LivePricingService.IMessageCallback.ShutDown
        _ns.Close()
        Globals.LastException = New Exception("The Live Pricing Serice has shut down.")
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have six wcf services that I'm hosting in a windows service. Everything works
I have a windows service hosting several WCF services. In my windows service I
We have an windows service written in .net, that is hosting WCF service. My
I have a Windows Service that is self hosting a Wcf service, this Wcf
We have a windows service that is self-hosting a WCF Data Service, using the
I have a wcf service that I am hosting within a windows service on
I have a WCF service and am hosting it in a Windows Service. I
I have a WCF service (MyService.svc) that im hosting under IIS 7.5. My .svc
I have created a windows service for the sole purpose of hosting a WCF
I have several resources that I'd like to expose using the WCF Web API.

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.