none
WCF Inter-proccess full duplex communications in Windows Forms C#.net application RRS feed

  • Question

  • Hi,

    I am learning about WCF and did this:

    http://dopeydev.com/wcf-interprocess-communication/

    It is working but I want to modify this a little because if you connect two or more clients to the same server, the server can communicate only with last client joinned. So, I need to keep tracking of all client instances but I don't know how to modify the code. I am trying for last 3 days without success.

    Can anybody help me a little with this learning?

    Thank You!
    Slash!


    "Can one man truly make difference?"

    Tuesday, April 7, 2015 5:33 PM

Answers

  • >[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

    No.  PerSession is the right choice there.  WCF will create a new instance of your service class to service each client.  I took a quick look at the sample code and it should work fine for multiple clients.

    You can track the clients, buy tracking the instances of your service class.  eg

    using System.ServiceModel;
    using System.Windows.Forms;
    
    namespace TestServer
    {
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
        public class TestService : ITestService
        {
            public static List<TestService> AllSessions = new List<TestService>();
            public void Connect()
            {
                Callback = OperationContext.Current.GetCallbackChannel<ICallbackService>();
                AllSessions.Add(this);
            }
    
            public static ICallbackService Callback { get; set; }
    
    
            public void ShowMessage(string message)
            {
                MessageBox.Show(message);
            }
        }
    }

    David


    David http://blogs.msdn.com/b/dbrowne/

    Tuesday, April 7, 2015 7:58 PM

All replies

  • Try by changing the [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] to 

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

    Check this detialed example about instance management in WCF

    http://www.codeproject.com/Articles/86007/ways-to-do-WCF-instance-management-Per-call-Per


    Fouad Roumieh

    Tuesday, April 7, 2015 6:39 PM
  • >[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

    No.  PerSession is the right choice there.  WCF will create a new instance of your service class to service each client.  I took a quick look at the sample code and it should work fine for multiple clients.

    You can track the clients, buy tracking the instances of your service class.  eg

    using System.ServiceModel;
    using System.Windows.Forms;
    
    namespace TestServer
    {
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
        public class TestService : ITestService
        {
            public static List<TestService> AllSessions = new List<TestService>();
            public void Connect()
            {
                Callback = OperationContext.Current.GetCallbackChannel<ICallbackService>();
                AllSessions.Add(this);
            }
    
            public static ICallbackService Callback { get; set; }
    
    
            public void ShowMessage(string message)
            {
                MessageBox.Show(message);
            }
        }
    }

    David


    David http://blogs.msdn.com/b/dbrowne/

    Tuesday, April 7, 2015 7:58 PM
  • Thank you!

    I did and it is working.

    Just another question:
    I need to send a message from Client A to Client B. So I am planing to create methods for clients to store information inside the server and an event that server will fire every time new information flag is set.

    Is this the right way to do it?


    "Can one man truly make difference?"

    Friday, April 17, 2015 2:36 PM