locked
Binding Configuration - Close Session RRS feed

  • Question

  • Hi, i have two questions:

     

    1) how can i create in code a new binding configuration, that i can add to my binding?  (likewise the config file). Or isn't that possible, and do i have to create a custom binding?  I would like to put the reliable session property of my nettcpbinding instance on false, but it's a read only property.

     

    2)

    On my client i have following code:

     

     

    NetTcpBinding binding = new NetTcpBinding();

    binding.TransferMode = TransferMode.Buffered;

    EndpointAddress addr = new EndpointAddress("net.tcp://localhost:10000/MyService");

    WCFServiceLibrary.IMyService myService = ChannelFactory<WCFServiceLibrary.IMyService>.CreateChannel(binding, addr);

    Console.WriteLine("Calling HelloWorld...");

    WCFServiceLibrary.MyData m = myService.HelloWorld();

    Console.WriteLine(m.sInfo);

    Console.WriteLine("OneWay 1...");

    myService.OneWay();

    Console.WriteLine("OneWay 2...");

    myService.OneWay();

    myService = null;

    Console.WriteLine("Closed...");

     

    how can i close the session from the client?  Normally i do this when i use a proxy, i call the proxy.close method.  but this doesn't work on my myService instance.  So how can i make sure i can close the session?

     

    Tuesday, May 29, 2007 6:31 PM

Answers

  • 1) I think you want tcpBinding.ReliableSession.Enabled = false (the .Enabled property is read-write).

     

    2) cast to IClientChannel "((IClientChannel)myService).Close()"

    Tuesday, May 29, 2007 6:38 PM
  • True... Actually, the class of the object returned from ChannelFactory.CreateChannel() implements it. In other words this is in the WCF framework itself (e.g. System.ServiceModel.Channels.ServiceChannel class). 

    So I would say it like this: if you want to access the channel, access the object returned by ChannelFactory.CreateChannel() via an IClientChannel interface.

     

    Makes sense?

     

    Cheers,

    Buddhike

    Wednesday, May 30, 2007 6:01 AM
  • Indeed; under the hood, WCF returns an object from CreateChannel that uses RealProxy/CLR magic to be able to cast to both your contract interface type (the T in ChannelFactory<T>) as well as the WCF IClientChannel type.
    Wednesday, May 30, 2007 6:35 AM
  • The ChannelFactory sample docs this:

    http://msdn2.microsoft.com/en-us/library/ms751400.aspx

     

    It's unfortunate to not see it doc'd here:

    http://msdn2.microsoft.com/en-us/library/ms576132.aspx

    ...I'll point that out to our docs guys.  Thanks for the input.

     

    Wednesday, May 30, 2007 7:39 AM

All replies

  • 1) I think you want tcpBinding.ReliableSession.Enabled = false (the .Enabled property is read-write).

     

    2) cast to IClientChannel "((IClientChannel)myService).Close()"

    Tuesday, May 29, 2007 6:38 PM
  • thx for the answers, about the second answer.  I can't test it out right now on this pc, but how does it come that i can cast my 'myService' to IClientChannel. 

     

    The create channel factory creates me an instance of WCFServiceLibrary.IMyService and this interface doesn't implement the IClientChannel. 

     

    kind regards

    Wednesday, May 30, 2007 5:31 AM
  • True... Actually, the class of the object returned from ChannelFactory.CreateChannel() implements it. In other words this is in the WCF framework itself (e.g. System.ServiceModel.Channels.ServiceChannel class). 

    So I would say it like this: if you want to access the channel, access the object returned by ChannelFactory.CreateChannel() via an IClientChannel interface.

     

    Makes sense?

     

    Cheers,

    Buddhike

    Wednesday, May 30, 2007 6:01 AM
  • Indeed; under the hood, WCF returns an object from CreateChannel that uses RealProxy/CLR magic to be able to cast to both your contract interface type (the T in ChannelFactory<T>) as well as the WCF IClientChannel type.
    Wednesday, May 30, 2007 6:35 AM
  • ok, thx guys for clearing this up for me, is that 'magic' documented Smile Because that's something i would never had guessed, i really tought the CreateChannel would return an object that only implements my contract interface, nothing else.

     

     

    Wednesday, May 30, 2007 7:30 AM
  • The ChannelFactory sample docs this:

    http://msdn2.microsoft.com/en-us/library/ms751400.aspx

     

    It's unfortunate to not see it doc'd here:

    http://msdn2.microsoft.com/en-us/library/ms576132.aspx

    ...I'll point that out to our docs guys.  Thanks for the input.

     

    Wednesday, May 30, 2007 7:39 AM