Using Configuration Files
This one is actually quite simple. Just place the following statements in the client’s configuration file:
When using IIS on the server side this is supported by default – i.e. you don’t have to change your server-side configuration file at all.
The standard way of specifying this for a server-side application would be:
Using code
First, you have to reference System.Runtime.Remoting.DLL and to include at least the following namespaces:
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
Then you can use the following code to add a binary formatter for an HttpChannel:
IDictionary props = new Hashtable();
props["name"] = “MyHttpChannel”;
props["port"] = 1234;
BinaryServerFormatterSinkProvider srv = new BinaryServerFormatterSinkProvider();
BinaryClientFormatterSinkProvider clnt = new BinaryClientFormatterSinkProvider();
HttpChannel channel = new HttpChannel(props,clnt,srv);
ChannelServices.RegisterChannel(channel);
If you only need either client or server side formatter, you can omit “the other” formatter and just pass null to the HttpChannel’s constructor. For a “client-only” channel, you can therefore use the following code:
BinaryClientFormatterSinkProvider clnt = new BinaryClientFormatterSinkProvider();
HttpChannel channel = new HttpChannel(null,clnt,null);
ChannelServices.RegisterChannel(channel);