locked
Different SessionID in multiple Proxy Client? RRS feed

  • Question

  • User328625153 posted

    Hi Hi,

    My WCF service is implemented using [InstanceContextMode = InstanceContextMode.Single] with an operation to return the [OperationContext.Current.SessionId] back to the client.

    In my client, I have created 2 proxies as shown below:

    private void button1_Click(object sender, EventArgs e)
            {
                if (proxy1 == null)
                {
                    proxy1 = new SpaceShipSvc.SpaceShipSvcClient("UseWSBinding");
                    proxy1.Open();
                }
    
                
                string tmp = proxy1.GetInstanceSessionInfo(); //this will return the OperationContext.Current.SessionId
                string sessionid = proxy1.InnerChannel.SessionId;
                
                listBox1.Items.Add(string.Format("Proxy1 <{0}>: {1}", sessionid, tmp));
            }
    
    
            private void button2_Click(object sender, EventArgs e)
            {
                if (proxy2 == null)
                {
                    proxy2 = new SpaceShipSvc.SpaceShipSvcClient("UseWSBinding");
                    proxy2.Open();                
                }
    
                
                string tmp = proxy2.GetInstanceSessionInfo();
                string sessionid = proxy2.InnerChannel.SessionId;
                listBox1.Items.Add(string.Format("Proxy2 <{0}>: {1}", sessionid,tmp));
            }

    The result is that proxy1 and proxy2 yield 2 different SessionID.

    My question is, if my service's instancecontextmode is single, shouldn't I be getting only one SessionID?

    Thanks Thanks.

    Tuesday, September 3, 2013 4:25 AM

Answers

  • User260886948 posted

    Hi,

    In the single mode, the SessionID will be different accroding to different Proxy client.
    As you said that by defining your service as [InstanceContextMode.Single], only 1 service instance will be created at the host and be shared with the multiple clients/proxies. But the SessionID is different, if your proxy client is different.

    Best Regards.

     

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 4, 2013 3:51 AM

All replies

  • User-760709272 posted

    Single just means that only one call will executed at a time.

    Tuesday, September 3, 2013 5:09 AM
  • User328625153 posted

    Pardon me ... I don't quite understand.

    By defining my service as [InstanceContextMode.Single], only 1 service instance will be created at the host and be shared with the multiple clients/proxies. With the 1 service instance, the variable declared in my service will be shared with the multiple clients/proxies. E.g.

    [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)] 
    public class CalculatorService : ICalculatorInstance 
    { 
       int instanceCount=0;
    
       public int getInstanceCount(){
            return instanceCount++;
       }
       
    }

    Both my proxyClient1 and proxyClient2 will share the same [instanceCount] variable. Therefore, in regardless of which proxyClient calls the [getInstanceCount()], the value returned will be {0,1,2,3,4 ...}.

    If that is the case, shouldn't both of my proxies contain the same sessionID?

    Tuesday, September 3, 2013 10:23 AM
  • User260886948 posted

    Hi,

    In the single mode, the SessionID will be different accroding to different Proxy client.
    As you said that by defining your service as [InstanceContextMode.Single], only 1 service instance will be created at the host and be shared with the multiple clients/proxies. But the SessionID is different, if your proxy client is different.

    Best Regards.

     

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 4, 2013 3:51 AM