.NET Remoting and callbacks
Just a brief note about something that caused me a lot of grief recently: .NET remoting, especially with events. The first problem I had was that callbacks were not being sent, because the client application had not registered a listening channel. The MSDN docs have a note about that (so you know it's a problem), but don't go out of their way to point to the solution:
using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; IChannel chan= new TcpChannel(0); ChannelServices.RegisterChannel(chan);As it turns out, this is all you need for thing to work with .Net 1.0. My problems did not disappear, however, because of security exceptions. This is the place where I wish whoever wrote the MSDN docs about code access security a very, very short life. I have never seen so many ways to avoid answering the first and foremost question that a programmer can have (i.e. "How do I configure the code to have the necessary permissions?") in a single piece of 'technical' writing. Anyhow, since I could care less about security in this particular instance (physically private and secure network), and since I am OK with all types being sent across using remoting, I did the following:
using System.Collections; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; using System.Runtime.Serialization.Formatters; Hashtable props= new Hashtable(); // High priority >100 to make sure that this channel gets used to receive the callbacks props["priority"]= "200"; props["port"]= "0"; BinaryServerFormatterSinkProvider servProvider= new BinaryServerFormatterSinkProvider(); // The default is Low - so only certain types can be remoted, set it to Full to avoid the whole issue servProvider.TypeFilterLevel= TypeFilterLevel.Full; IChannel chan= new TcpChannel(props, null, servProvider); ChannelServices.RegisterChannel(chan);Aaaargh! The solution is so easy, but you have to dig it out of the documentation character by character. In the end, it was a random blog post somewhere that answered my question (sorry, no link - I already lost it. That's why this is here.) Finally, a friendly reminder - make sure that the callback handlers are public (or accessible to whoever fires them).