Discuz!NT
欢迎 游客 , 注册 | 登录 | 会员 | 界面 | 简洁版本 | 在线 | 帮助
商都网教育宝典宝库

发表新主题 回复该主题
本主题被查看1273次, 共1个帖子, 1页, 当前为第1页     选择页数: 1      跳转到第   上一主题   下一主题
标题: 调用web services提示Access Denied的解决办法[整理]
张小峰
超级版主
UID: 14
来自:
精华: 4
积分: 313
帖子: 285
注册: 2007-8-23 10:27:00
状态: 离线
威望: 8.00
金钱: 75.55 元
只看楼主 2007-08-23 15:40
调用web services提示Access Denied的解决办法[整理]
现象:
asp.net中调用web services时提示错误:
请求因  HTTP  状态  401  失败:Access  Denied。 
将web services放到另一台服务器问题又不存在该问题。
解决办法:
1.新建方法:
#region GetCredentialCache
/// <summary>
/// 获取CredentialCache
/// 解决访问web service时提示没有权限的问题
/// </summary>
/// <returns></returns>

public static CredentialCache GetCredentialCache()
{
//权限验证web services地址
string WSUrl = RightsServicesUrl;
//Create an instance of the CredentialCache class.
CredentialCache cache = new CredentialCache();
// Add a NetworkCredential instance to CredentialCache.
// Negotiate for NTLM or Kerberos authentication.

cache.Add( new Uri(WSUrl), "Negotiate", new NetworkCredential("域用户名", "域密码", "域"));
return cache;
}
#endregion
2.为web services指定CredentialCache
web services引用名为RightsControl,添加如下代码:
RightsControl rightsControl = new RightsControl();
//为web services指定CredentialCache,最重要的就是这一句
rightsControl.Credentials = GetCredentialCache();
//调用rightsControl的方法
#1  
发表新主题 回复该主题
本主题被查看1273次, 共1个帖子, 1页, 当前为第1页     选择页数: 1      跳转到第







现在的时间是 2008-10-08 03:55:37

版权所有 商都网教育宝典
         Powered by Discuz!NT 1.0.6666    Copyright © 2001-2008 Comsenz Inc.
Processed in 0 seconds