HTTP request is unauthorized with client authentication scheme 'Anonymous'.

简介:

当使用VS2008 作为client call sharepoint的service(WCF)的时候显示异常:

 HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'

 

我的解决方法:

1,使用http的endpoint:

<security mode="TransportCredentialOnly">

 

2,使用https的endpoint:

<security mode="Transport">

 

粘贴出client端的app.config

 

复制代码

   
   
<? xml version="1.0" encoding="utf-8" ?>
< configuration >
< system.serviceModel >
< bindings >
< basicHttpBinding >
< binding name ="BasicHttpBinding_BusinessDataCatalogSharedService"
closeTimeout
="00:01:00" openTimeout ="00:01:00" receiveTimeout ="00:10:00"
sendTimeout
="00:01:00" allowCookies ="false" bypassProxyOnLocal ="false"
hostNameComparisonMode
="StrongWildcard" maxBufferSize ="999999"
maxBufferPoolSize
="9999999" maxReceivedMessageSize ="999999"
messageEncoding
="Mtom" textEncoding ="utf-8" transferMode ="Buffered"
useDefaultWebProxy
="true" >
< readerQuotas maxDepth ="99" maxStringContentLength ="999999" maxArrayLength ="999999"
maxBytesPerRead
="999999" maxNameTableCharCount ="999999" />
< security mode ="TransportCredentialOnly" >
< transport clientCredentialType ="Ntlm" proxyCredentialType ="None"
realm
="" >
< extendedProtectionPolicy policyEnforcement ="Never" />
</ transport >
< message clientCredentialType ="UserName" algorithmSuite ="Default" />
</ security >
</ binding >
< binding name ="BasicHttpBinding_BusinessDataCatalogSharedService1"
closeTimeout
="00:01:00" openTimeout ="00:01:00" receiveTimeout ="00:10:00"
sendTimeout
="00:01:00" allowCookies ="false" bypassProxyOnLocal ="false"
hostNameComparisonMode
="StrongWildcard" maxBufferSize ="999999"
maxBufferPoolSize
="9999999" maxReceivedMessageSize ="999999"
messageEncoding
="Mtom" textEncoding ="utf-8" transferMode ="Buffered"
useDefaultWebProxy
="true" >
< readerQuotas maxDepth ="99" maxStringContentLength ="999999" maxArrayLength ="999999"
maxBytesPerRead
="999999" maxNameTableCharCount ="999999" />
< security mode ="Transport" >
< transport clientCredentialType ="Ntlm" proxyCredentialType ="None"
realm
="" >
<!-- <extendedProtectionPolicy policyEnforcement="Never" /> -->
</ transport >
< message clientCredentialType ="UserName" algorithmSuite ="Default" />
</ security >
</ binding >
</ basicHttpBinding >
</ bindings >
< client >
< endpoint address ="http://SUT02/_vti_bin/BdcAdminService.svc"
binding
="basicHttpBinding" bindingConfiguration ="BasicHttpBinding_BusinessDataCatalogSharedService"
contract
="BusinessDataCatalogSharedService" name ="BasicHttpBinding_BusinessDataCatalogSharedService" />
< endpoint address ="https://SUT02:443/_vti_bin/BdcAdminService.svc"
binding
="basicHttpBinding" bindingConfiguration ="BasicHttpBinding_BusinessDataCatalogSharedService1"
contract
="BusinessDataCatalogSharedService" name ="BasicHttpBinding_BusinessDataCatalogSharedService1" />
</ client >
</ system.serviceModel >
</ configuration >
复制代码

 

client端的代码如下:

 

复制代码

   
   
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;
}
复制代码

 

目录
相关文章
remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2
remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2
4422 0
|
6月前
|
前端开发 对象存储 数据安全/隐私保护
阿里云前端直传has been blocked by CORS policy: Response to preflight request doesn‘t pass access control
阿里云前端直传has been blocked by CORS policy: Response to preflight request doesn‘t pass access control
679 2
|
7月前
|
应用服务中间件 网络安全 nginx
Client sent an HTTP request to an HTTPS server
Client sent an HTTP request to an HTTPS server
1048 0
|
7月前
|
Java 应用服务中间件
HTTP Status 404(The requested resource is not available)
HTTP Status 404(The requested resource is not available)
46 0
|
开发工具 数据安全/隐私保护
The request you have made requires authentication. (HTTP 401)
The request you have made requires authentication. (HTTP 401)
1393 0
The request you have made requires authentication. (HTTP 401)
requests InsecureRequestWarning: Unverified HTTPS request is being made.
requests InsecureRequestWarning: Unverified HTTPS request is being made.
1283 0
|
安全 数据库 数据安全/隐私保护
HTTP Authorization
HTTP Authorization
528 0
remote: Incorrect username or password ( access token ) fatal: Authentication failed for 'https:/...
remote: Incorrect username or password ( access token ) fatal: Authentication failed 开门见山—— 解决方法: 1.
5446 0
|
Java
[http]request,session,application
1. request request是表示一个请求,只要发出一个请求就会创建一个request,它的作用域:仅在当前请求中有效。
1148 0