之前开发时就碰到这个问题,如果通过HTTP代理访问Remoting远程对象,找了很久的资料,都没有结果。最终在一个英文的BLOG看到解决方案,才得于解决。今天看代码,就整理出来,分享下。随然不知道WCF什么应用起来怎么样,但我觉得.Net Remoting不可能一下子给替掉.

Code
//服务端信道接收器
BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
//客户端信道接收器
BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
//反序列级别
serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
//
IDictionary props = new Hashtable();
props["port"] = 0;
props["TypeFilterLevel"] = "Full";
IWebProxy proxy;
WebProxy proxyObject = new WebProxy("http://192.168.1.1:8080",true);
HttpClientChannel chann = new HttpClientChannel(props, clientProv);
proxy = proxyObject;
NetworkCredential ProxyCredentials = new NetworkCredential("userid",
"password");
proxy.Credentials = ProxyCredentials;
FieldInfo proxyObjectFieldInfo = typeof(HttpClientChannel).GetField("_proxyObject",
BindingFlags.Instance | BindingFlags.NonPublic);
proxyObjectFieldInfo.SetValue(chann, proxy);
ChannelServices.RegisterChannel(chann, false);
备注:这样我们就不能使用"配置文件"的方式访问远程服务对象了.得用编码的方式访问远程对象.