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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:32:24+00:00 2026-06-06T11:32:24+00:00

I am trying to make a simple windows service that maintains a queue of

  • 0

I am trying to make a simple windows service that maintains a queue of integers and accepts new integers from other applications via a WCF call. My current implementation seems to maintain separate queues for each application which communicates with it, which is not what I want.

I started by following the instructions at from Microsoft on How to: Host a WCF Service in a Managed Windows Service.

My WindowsService class looks like this:

public class MyWindowsService : ServiceBase{
    public ServiceHost serviceHost = null;

    public MyWindowsService(){
        ServiceName = "AdHocReportService";
    }
    public static void Main(){
        ServiceBase.Run(new MyWindowsService());
    }

    protected override void OnStart(string[] args){
        if (serviceHost != null)
            serviceHost.Close();

        serviceHost = new ServiceHost(typeof(MyService));
        serviceHost.Open();
    }
    protected override void OnStop(){
        if (serviceHost != null){
            serviceHost.Close();
            serviceHost = null;
        }
    }
}

In my Service class I have a queue and an Add method. The add method returns the count of items in the queue after the add. The code looks like this:

public class MyService : IMyService
{
    private Queue<int> myQueue= new Queue<int>();

    public int Add(int reportId)
    {
        myQueue.Enqueue(reportId);
        return myQueue.Count;
    }
}

Lastly, I test my service using the following code in a ConsoleApp:

MyServiceClient client = new MyServiceClient();
int count = client.Add(10);
Console.WriteLine(count);  //prints 1
count = client.Add(25);
Console.WriteLine(count);  //prints 2
Console.ReadLine();

I would expect this to print 1 and 2 the first time my test is run, then 3 and 4 the second time, and then 5 and 6 the third and so on. However, it simply returns 1 and 2 each time, as if the Console App is instantiating the object itself and not operating on the object inside the Windows Service. What am I not understanding?

  • 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-06T11:32:26+00:00Added an answer on June 6, 2026 at 11:32 am

    I think you want a singleton WCF service. See here.

    By default, the instance mode for a WCF service is per-call. So an instance of your service is being created by the host for each call you make.

    Note: When using a singleton service, your operations need to be thread safe. So I suggest switching from a Queue to a ConcurrentQueue, so you can handle multiple concurrent clients.

    Alternative: Use a MSMQ binding. This will ensure you that all of your incoming messages are queued out of process, therefore persisted between restarts too.

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

Sidebar

Related Questions

i'm new in a web service. i'm trying to make a simple web service
I'm trying to make a simple Windows form app that does things. I'd like
I'm trying to make a simple build script that would work on windows and
I am trying to make a simple Windows Form application that will show different
I'm trying to make simple website with content background combined from 3 images: top
I am fairly new to iOS development and trying make a simple app which
im trying to make a simple search on my database from the index action
Using C++/CLI and Windows Forms, I'm trying to make a simple scrollable list of
I am trying to make a Django website be a simple Windows executable. I've
I am trying to make a simple 3D game for windows with XNA 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.