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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:34:50+00:00 2026-05-22T11:34:50+00:00

I create a WCF SOAP server with an operation that takes some time to

  • 0

I create a WCF SOAP server with an operation that takes some time to perform:

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    string LongRunningOperation();
}

[ServiceBehavior(
    ConcurrencyMode = ConcurrencyMode.Multiple,
    UseSynchronizationContext = false,
    InstanceContextMode = InstanceContextMode.Single)]
class MyService : IMyService
{
    public string LongRunningOperation()
    {
        Thread.Sleep(20000);
        return "Hey!";
    }
}

class Program
{
    static void Main(string[] args)
    {
        MyService instance = new MyService();
        ServiceHost serviceHost = new ServiceHost(instance);
        BasicHttpBinding binding = new BasicHttpBinding();
        serviceHost.AddServiceEndpoint(typeof(IMyService), binding, "http://localhost:9080/MyService");
        serviceHost.Open();
        Console.WriteLine("Service running");
        Thread.Sleep(10000);
        serviceHost.Close();
        Console.WriteLine("Service closed");
        Thread.Sleep(30000);
        Console.WriteLine("Exiting");
    }
}

The ServiceHost is opened, and after 10 seconds I close it.

When calling serviceHost.Close(), all clients currently connected, waiting for LongRunningOperation to finish, are inmediately disconnected.

Is there a wait of closing the ServiceHost in a cleaner way? That is, I want to disable the service listeners, but also wait for all currently connected clients to finish (or specify a maximum timeout).

  • 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-22T11:34:51+00:00Added an answer on May 22, 2026 at 11:34 am

    In principle, I think something like the following should be possible, though I haven’t implemented it to confirm all the details:

    • Implement a custom IOperationInvoker
      wrapping the Dispatcher’s normal
      OperationInvoker (you’ll want an IServiceBehavior to install the wrapped invoker when the service dispatcher runtime is built)
    • the custom invoker would mostly delegate to the real one, but would also provide
      “gate-keeper” functionality to turn away
      new requests (e.g. raise a some kind of exception) when the service host is about
      to be shut down.
    • it would also keep track of operation invocations still in
      progress and set an event when the last operation invocation finishes or times out.
    • the main hosting thread would then wait on the invoker’s “all finished” event before calling serviceHost.Close().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a WCF SOAP service using VS 2008 that works server side. I
I am currently trying to create a REST proxy that calls a WCF SOAP
Given a contract such as: [ServiceContract] public interface IService { [OperationContract] [WebGet(UriTemplate = GetData/{id}.{format})]
How to create Net.TCP WCF binding for\using SOAP 1.1? Is it posible? If yes.
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Hi I want to create a WCF service that have login method, which is
Is it possible to create a WCF service (web service) that only accepts a
How to create socket-based ( Binary Socket) WCF server server with WCF, C#? What
Is it possible to create a single .svc file (WCF Service) that I can
I'm new to WCF I have to create a WCF service that receives plain

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.