DCSIMG
February 2009 - Posts - Sig-

Sig-

Code and stuff.

February 2009 - Posts

IpcChannel and Remoting Events

Just solved a problem that I had a hard time googling to solve, so I wanted the next guy to have an easier time :

When creating a remoting connection from a client to a server, and you want the server to be able to raise events back to the client,
you must set a property called "tokenImpersonationLevel" to "impersonation" on the dictionary used to initialize the channel.

i.e. :

        /// <summary>

        /// Setup a client channel for the server to use during callbacks (events)

        /// </summary>

        private void SetupRemotingChannel()

        {

            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();

            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();

            IDictionary props = new Hashtable();

 

            props["name"] = props["portName"] = _clientChannelName = _clientChannelBaseName + Guid.NewGuid().ToString();

            props["tokenImpersonationLevel"] = "impersonation";

 

            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

 

            IpcChannel chan = new IpcChannel(props, clientProv, serverProv);

            ChannelServices.RegisterChannel(chan, true);

        }

Posted: Feb 22 2009, 04:00 PM by silver83 | with no comments
תגים: