如题:在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有没有遇到此类情况的啊,你们是怎么解决的,更希望各位高手提些宝贵的意见,小弟感激不尽。谢谢。

解决方案 »

  1.   

    谢谢楼上的好心人。其它DGDJ有遇到这类问题的吗?
      

  2.   

    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登录用户名", "登录密码");