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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:06:24+00:00 2026-06-03T17:06:24+00:00

Class: [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerSession)] public class MainService : IChat { IChatCallback

  • 0

Class:

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerSession)]
public class MainService : IChat
{
    IChatCallback ChatCallback = OperationContext.Current.GetCallbackChannel<IChatCallback>();
    Chat chat = new Chat(this);
    public void ShowChat()
    {
        chat.Show();
    }
    public void SendInstantMessage(string user, string message)
    {
        chat.RaiseMsgEvents(user, message);
        ChatCallback.InstantMessage(user, message);
    }
 }

Form:

public partial class Chat : Form
{
    MainService service;

    public Chat(MainService service)
    {
        InitializeComponent();
        OnMsgReceivedEvent += new OnMsgReceived(callback_OnMsgReceivedEvent);
        this.service = service;
    }

    private void btnSend_Click(object sender, EventArgs e)
    {
        service.SendInstantMessage("Admin", txtMsg.Text);
    }
 }

The mainForm use the class like this:

 public partial class Form1 : Form
 {
    ServiceHost host;
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        host = new ServiceHost(typeof(WCF_Server.MainService));
        host.Open();
    }
 }

In the main form, i just pass the class, no initializing, but in the class when ShowChat() called i need to show the chat form and get to this class method so i can send messages.

  • 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-03T17:06:27+00:00Added an answer on June 3, 2026 at 5:06 pm

    .NET is an object oriented language. In fact, every class is an object.

    The error you are getting is because you’re instantiating an object with “this” on the global level.

    UPDATE

    Based on your update you could do the following and it will work. You might want to refactor this some more to ensure that it’s not going to break any business rules etc.

    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerSession)]
    public class MainService : IChat
    {
        IChatCallback ChatCallback = OperationContext.Current.GetCallbackChannel<IChatCallback>();
        //Changed this to be just a declaration. This will be null,
        // as there is no object yet, this is really just a pointer to nothing.
        //This tells the system that you might/are planning to use an object called 
        //chat, but it doesn't exist yet.
        Chat chat;
    
        // Get your default constructor going. This will create the actual chat object, allowing the rest of your class to access it.
        public MainService()
        {
             //instantiate it! (or as some of our co-ops say "We're newing it")
             chat = new Chat(this);
        }
    
        //now that chat is actually instantiated/created you can use it.
        public void ShowChat()
        {
            chat.Show();
        }
        public void SendInstantMessage(string user, string message)
        {
            chat.RaiseMsgEvents(user, message);
            ChatCallback.InstantMessage(user, message);
        }
     }
    

    This is just a personal pet peeve, but having a function parameter the same name as a global variable is… well for me a no no. I noticed this on your Chat.Chat(MainService) function.

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

Sidebar

Related Questions

I have a net tcp WCF service as follows [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] public class
I've implemented a WCF service as such: [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext=false)]
I have a service configured with following attributes [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
I have a WCF service code like this: [ServiceContract] [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode =
I have a WebService (.svc) class with [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single)] and I want to
class test <T> where T : class { public void Write<T>() { Console.Write(typeof(T).FullName); }
class foo { public: void say_type_name() { std::cout << typeid(this).name() << std::endl; } };
class Widget { public: Widget() { cout<<~Widget()<<endl; } ~Widget() { cout<<~Widget()<<endl; } void* operator
class Foo(){ public List<string> SomeCollection; } I need to implement an event which can
class B{ private: void DoSomething(); } class W{ private: class D: public B{ }

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.