HTTP request is unauthorized with client authentication scheme 'Anonymous'.
2010-06-29 14:12
1046 查看
当使用VS2008 作为client call sharepoint的service(WCF)的时候显示异常:
HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'[b]代码
HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'[b]代码
static void Main(string[] args) { BusinessDataCatalogSharedServiceClient client = new BusinessDataCatalogSharedServiceClient("BasicHttpBinding_BusinessDataCatalogSharedService1"); client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; client.ClientCredentials.UserName.UserName = @"domain\userName"; client.ClientCredentials.UserName.Password = "Password"; client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("username", "Password", "domain"); AcceptAllCertificate(); try { Guid guid = client.GetServiceApplicationId(); } catch (Exception ex) { throw; } } /// <summary> /// Case request Url include HTTPS and TCP prefix, use this function to avoid closing base connection. /// Local client will accept all certificate after execute this function. /// </summary> public static void AcceptAllCertificate() { ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate); } /// <summary> /// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication. /// In our adapter,we make this method always return true, make client can communicate with server under HTTPS without a certification. /// </summary> /// <param name="sender">An object that contains state information for this validation.</param> /// <param name="certificate">The certificate used to authenticate the remote party.</param> /// <param name="chain">The chain of certificate authorities associated with the remote certificate.</param> /// <param name="sslPolicyErrors">One or more errors associated with the remote certificate.</param> /// <returns>A Boolean value that determines whether the specified certificate is accepted for authentication.</returns> private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }
相关文章推荐
- Web service: The HTTP request is unauthorized with client authentication scheme 'Anonymous'.....
- The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the serv
- Web Service 之 Exception: "The HTTP request is unauthorized with client authentication scheme......"
- The request failed with HTTP status 401: Unauthorized. SSRS 2008
- Sharepoint client model 中出现Cannot invoke HTTP DAV request. There is a pending query 的解决办法
- scala: How to write a simple HTTP GET request client in Scala (with a timeout)
- Web Service Error: “The request failed with HTTP status 401: Unauthorized.”
- The request failed with HTTP status 401: Unauthorized
- Web Service Error: “The request failed with HTTP status 401: Unauthorized.”
- [原]openstack-kilo--issue(十三)Unauthorized: The request you have made requires authentication. (HTTP 401) (Request
- 关于No mapping found for HTTP request with URI和in DispatcherServlet with name 'qht_client'
- 访问WebService出现IIS错误:The request failed with HTTP status 401: Unauthorized
- C#: Create a WebRequest with HTTP Basic Authentication
- C#: Create a WebRequest with HTTPClient
- @FeignClient with top level @RequestMapping annotation is also registered as Spring MVC handler
- The request failed with HTTP status 401: Unauthorized
- Web Service Error: “The request failed with HTTP status 401: Unauthorized.”-ZT
- "/usr/local/openresty/nginx/html/index.html" is forbidden (13: Permission denied), client: 10.0.4.118, server: localhost, request: "GET / HTTP/1.1"
- Web Service出现The request failed with HTTP status 401: Unauthorized错误
- GET Request with HttpClient