在Winform程序中引用一个WebServices,调用其中的方法时出错了,高手请进,告诉小弟怎么来解决。

yezi_1105 2009-05-18 02:11:41
如题:在Winform程序中引用一个WebServices,调用其中的方法时,出现的错误提示如下
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'

但是在Web程序中却没有问题,看起来是权限的问题。
在Web中是这样设置的:sr.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; (sr为Webservices中类的实例)
不知道各位XDJM有没有遇到此类情况的啊,你们是怎么解决的,更希望各位高手提些宝贵的意见,小弟感激不尽。谢谢。
...全文
133 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
LutzMark 2009-05-21
  • 打赏
  • 举报
回复
Webservices启用了NTLM验证

try

引用 System.Net;

//windows集成验证:
YourUpLoadServiceRef.WebServiceName ws= new YourUpLoadServiceRef.WebServiceName ();
// Create a new instance of CredentialCache.
CredentialCache credentialCache = new CredentialCache();
// Create a new instance of NetworkCredential using the client credentials.
NetworkCredential credentials = new NetworkCredential("windows登录用户名", "登录密码");
// Add the NetworkCredential to the CredentialCache.
credentialCache.Add(new Uri(math.Url), "NTLM", credentials);
// Add the CredentialCache to the proxy class credentials.
math.Credentials = credentialCache;
// Call the method on the proxy class.
string Str = math.HelloWorld("keycom");

//基本身份验证:
YourUpLoadServiceRef.WebServiceName ws= new YourUpLoadServiceRef.WebServiceName ();
ws.Credentials = new System.Net.NetworkCredential("windows登录用户名", "登录密码");
yezi_1105 2009-05-20
  • 打赏
  • 举报
回复
问题还是没有解决啊,各位再帮我想想办法啊,快要交差了
烈火蜓蜻 2009-05-18
  • 打赏
  • 举报
回复
也许是你的代理类有问题吧
yezi_1105 2009-05-18
  • 打赏
  • 举报
回复
谢谢楼上的好心人。其它DGDJ有遇到这类问题的吗?
lcdcau 2009-05-18
  • 打赏
  • 举报
回复
没遇到过,帮你顶

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧