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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:43:15+00:00 2026-05-26T01:43:15+00:00

The main goal is to let users send message to the host. The host

  • 0

The main goal is to let users send message to the host. The host will think for two seconds, and then with DUAL, will send a message back. This is working fine for me.

The thing is, for every user who send a message, I’m subscribing him to a list. The thing I’m trying to accomplish is, if the user Console.Readline() == "b" ( brodadcast ), send all the subscribers "Hello".

But the list of subscribers is at the service, and the Console.Readline() is at the host.

The host:

static void Main(string[] args)
{
     ServiceHost duplex = new ServiceHost(typeof (ServiceClass));
     duplex.Open();
     Console.WriteLine("Press 'b' To Broadcast All subscibers : Hello");
     if (Console.ReadLine()=="b")
     {
         foreach (var registered in lstOfRegisteredUsers) //<== I cant access lstOfRegisteredUsers because its on the Service Class.
         {
              registered.SendBack("Hello");
         }
     }
     Console.WriteLine("Host is running, press <ENTER> to exit.");             
      Console.ReadLine();
}

The service:

public class ServiceClass : ISend
{
    public List<ISendBack> lstOfRegisteredUsers = new List<ISendBack>();

    public void Send(string data)
    {    
        ISendBack callback = OperationContext.Current.GetCallbackChannel<ISendBack>();
        lstOfRegisteredUsers.Add(callback); // <== here i'm adding subscribers for future broadcast " hello".
        Console.WriteLine("goind to process " + data);
        System.Threading.Thread.Sleep(2000);
        callback.SendBack("done " +data);
    }      
}

How can I send from the host, to each of the subscribers: “hello”?

  • 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-26T01:43:16+00:00Added an answer on May 26, 2026 at 1:43 am

    If I understand correctly then you wish to broadcast a message to each of your service’s callback clients if a key-press input is received into the console application hosting your service?

    To do this you need to be able to call into your service instance from your host application.

    This can be achieved by creating an instance of your service class within your host. Then when you create your ServiceHost you pass the instance into the ServiceHost constructor. Then in your service you have a method which does the actual callback and you can call it.

    For example:

    // Create an instance of your service class
    ServiceClass sc = new ServiceClass();
    
    // Instantiate new ServiceHost and pass in the instance as a singleton
    serviceHost = new ServiceHost(sc, "(Service uri here)");
    
    // Call the method on the service (which then calls the clients)
    sc.DoCallbacks();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My main goal is to get this up and running. My hook gets called
In this project there is going to be two .exe files: Main, in this
My main goal is to change the volume on one sound card based on
Current, I've got a stored procedure that has a main goal of doing a
For homework, I need to build a small java application.The main goal is to
My Goal I would like to have a main processing thread (non GUI), and
My goal is to maintain a web file server separately from my main ASP.NET
Goal: Create Photomosaics programmatically using .NET and C#. Main reason I'd like to do
Is there a Maven phase or goal to simply execute the main method of
this is my first question on stack overflow, so be gentle. Let me first

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.