我开发了远程服务(在ISS中托管.NET类型) . IIS配置为使用“集成Windows身份验证” .
当我在“localhost”上执行单元测试服务时,它完美地工作(下面的代码是我用来测试的代码),但在我将服务部署到测试服务器(在另一个域中)后,它开始抛出“System.Net.WebException:远程服务器返回错误:(401)未经授权 . ”例外 .
string url = string.Concat(@"http://", serverName, "/", ServiceName);
IDictionary props = new Hashtable();
props["useDefaultCredentials"] = true;
props["useAuthenticatedConnectionSharing"] = true;
BinaryServerFormatterSinkProvider srv = new BinaryServerFormatterSinkProvider();
BinaryClientFormatterSinkProvider clnt = new BinaryClientFormatterSinkProvider();
this.channel = new HttpChannel(props, clnt, srv);
ChannelServices.RegisterChannel(this.channel, false);
IMyService service = Activator.GetObject(typeof(IMyService), url) as IMyService;
service.GetData();// this error returns "System.Net.WebException: The remote server returned an error: (401) Unauthorized." exception.
可能是什么问题?它与域名相关吗?可能与默认Web代理的配置有关吗?
1 回答
您使用的凭据是什么?系统是否使用Windows身份验证?如果是,那么其他域是否接受您域中的用户?
您可能必须在域之间定义信任关系,或使用服务器域的不同且适当的凭据登录 .