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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:38:53+00:00 2026-06-01T15:38:53+00:00

I’m pretty new to programming, so bear with me if my question isn’t specific

  • 0

I’m pretty new to programming, so bear with me if my question isn’t specific enough. Right now I’m trying to make a simple Client Logon to my server. So the server App knows which users are connected. When a client connects I want an event to fire on the server that update the userlist. But it doesn’t and I can’t figure out why. Hope you can help.

In the codes I have removed how the users should be displayed in the serverApp. Right now I just need the event to work.

In my Service Library:

INetworkService contract:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace NetworkLib
{
    [ServiceContract]
    public interface INetworkService
    {
        [OperationContract]
        void Logon(UserInfo userInfo);

        [OperationContract]
        void Logout();
    }
}

NetworkService Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace NetworkLib
{
    public class NetworkService : INetworkService
    {
        public event EventHandler UserListChanged;

        public void Logon(UserInfo userInfo)
        {
            OnUserListChanged();
        }

        public void Logout()
        {
            OnUserListChanged();
        }

        private void OnUserListChanged()
        {
            var handler = UserListChanged;
            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
    }
}

UserInfo Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace NetworkLib
{
    [DataContract]
    public class UserInfo
    {
        [DataMember]
        public string Name;
    }
}

In my ServerApp (WPF):

using System.ServiceModel;
using NetworkLib;

namespace ServerApp
{
    public partial class MainWindow : Window
    {

        NetworkService networkService;

        public MainWindow()
        {
            InitializeComponent();

            ServiceHost host = new ServiceHost(typeof(NetworkService));

            host.Open();

            networkService = new NetworkService();

            networkService.UserListChanged += networkService_UserListChanged;

        }

        private void networkService_UserListChanged(object sender, EventArgs e)
        {
            MessageBox.Show("It Works!");
        }
    }
}

In my ClientApp (WPF): (Have made a Service Reference to the Server)

namespace ClientApp
{

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            ServiceReference.NetworkServiceClient proxy = new ServiceReference.NetworkServiceClient();

            ServiceReference.UserInfo userInfo = new ServiceReference.UserInfo();

            userInfo.Name = "Test";

            proxy.Logon(userInfo);

        }
    }
}
  • 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-01T15:38:54+00:00Added an answer on June 1, 2026 at 3:38 pm

    When creating your ServiceHost, you should provide NetworkService instance instead of typeof(NetworkService)

    ServiceHost host = new ServiceHost(networkService);
    

    You need to initialize it first, of course.

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

Sidebar

Related Questions

Alright I'm pretty new to programming and stuff and I'm now trying to code
I'm pretty new to Android programming so bear with me. I was wondering if
I'm pretty new to programming, and I'm creating a simple text-based game.> I'm wondering
I am pretty new to programming on Linux. I am trying to implement a
Pretty new to C# but not new in programming in generally. I'm still trying
I'm pretty new at this programming thing...and I need to make a program which
I am pretty new to iphone programming therefore I apologize if my question could
I'm pretty new to Python programming so I have this question: How can I
I'm still pretty new to programming so I have somewhat of a noob question.
I'm pretty new to programming for Linux environments, so I don't exactly know what

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.