问题描述:remoting的server是IIS作host,Client环境访问internet要通过firewall,所以报
The remote server returned an error: (407) Proxy Authenticaztion Required的错误.
原因:访问远程站点的时候,用了代理,没有设置用户名/密码.
解决:你可以显示的拒绝用代理,或者制定访问用代理的用户名和密码.
如果你的程序需要设置代理,比如remoting host在internet外面。请设置一个代理
*/
//System.Runtime.Remoting.Channels.ch
HttpChannel theChannel = (HttpChannel)ChannelServices.GetChannel("http");
setChannelProxy(theChannel,null);
//setChannelProxy(theChannel,youproxy);
*/
//System.Runtime.Remoting.Channels.ch
HttpChannel theChannel = (HttpChannel)ChannelServices.GetChannel("http");
setChannelProxy(theChannel,null);
//setChannelProxy(theChannel,youproxy);
/// <summary>
/// 设置remoting 客户端proxy 的代码快
/// 目前remoting 的httpclientchannel 并没有提供直接设置代理的方法,所以需要用反射来设置。</summary>
/// <param name="channel"></param>
/// <param name="proxy"></param>
private static void setChannelProxy( HttpChannel channel, IWebProxy proxy )
{
//if configuration not set proxyserver then set channel's proxyName Properties to null
if (proxy==null)
{
channel.Properties["proxyName"]=null;
//saveProxyToReg(null,null,null,null,null);
return;
}
//channel.Properties["proxyName"]=null;
//use reflection to set the channel's proxyObject
FieldInfo clientChannelFieldInfo =
typeof(HttpChannel).GetField("_clientChannel",
BindingFlags.Instance | BindingFlags.NonPublic);
HttpClientChannel clientChannel = (HttpClientChannel)
clientChannelFieldInfo.GetValue(channel);
FieldInfo proxyObjectFieldInfo =
typeof(HttpClientChannel).GetField("_proxyObject",
BindingFlags.Instance | BindingFlags.NonPublic);
proxyObjectFieldInfo.SetValue( clientChannel, proxy );
// use GlobalProxySelection to set other web request
GlobalProxySelection.Select = proxy;
}
/// 设置remoting 客户端proxy 的代码快
/// 目前remoting 的httpclientchannel 并没有提供直接设置代理的方法,所以需要用反射来设置。</summary>
/// <param name="channel"></param>
/// <param name="proxy"></param>
private static void setChannelProxy( HttpChannel channel, IWebProxy proxy )
{
//if configuration not set proxyserver then set channel's proxyName Properties to null
if (proxy==null)
{
channel.Properties["proxyName"]=null;
//saveProxyToReg(null,null,null,null,null);
return;
}
//channel.Properties["proxyName"]=null;
//use reflection to set the channel's proxyObject
FieldInfo clientChannelFieldInfo =
typeof(HttpChannel).GetField("_clientChannel",
BindingFlags.Instance | BindingFlags.NonPublic);
HttpClientChannel clientChannel = (HttpClientChannel)
clientChannelFieldInfo.GetValue(channel);
FieldInfo proxyObjectFieldInfo =
typeof(HttpClientChannel).GetField("_proxyObject",
BindingFlags.Instance | BindingFlags.NonPublic);
proxyObjectFieldInfo.SetValue( clientChannel, proxy );
// use GlobalProxySelection to set other web request
GlobalProxySelection.Select = proxy;
}