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'trans.gif?cver=2.15.0079.0

 

我的解决方法:

1,使用http的endpoint:

<security mode="TransportCredentialOnly">

 

2,使用https的endpoint:

<security mode="Transport">

 

粘贴出client端的app.config

 

ExpandedBlockStart.gif
复制代码
 
  
<? 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端的代码如下:

 

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

 

目录
相关文章
|
6月前
|
Web App开发 缓存 安全
关于 HTTP 响应头字段 Strict-Transport-Security
关于 HTTP 响应头字段 Strict-Transport-Security
102 0
|
7天前
|
Java 应用服务中间件
HTTP Status 404(The requested resource is not available)
HTTP Status 404(The requested resource is not available)
10 0
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
3643 0
|
2月前
|
前端开发 JavaScript 数据安全/隐私保护
什么是 HTTP 307 Internal Redirect
什么是 HTTP 307 Internal Redirect
148 0
|
6月前
|
Web App开发 JSON 数据格式
使用 http-proxy 代理 HTTP 请求时遇到的 the requested url is invalid 错误消息
使用 http-proxy 代理 HTTP 请求时遇到的 the requested url is invalid 错误消息
104 0
|
开发工具 数据安全/隐私保护
The request you have made requires authentication. (HTTP 401)
The request you have made requires authentication. (HTTP 401)
1087 0
The request you have made requires authentication. (HTTP 401)
|
Web App开发 应用服务中间件
tomcat报错:Error parsing HTTP request header
tomcat报错:Error parsing HTTP request header
250 0
|
安全 数据库 数据安全/隐私保护
HTTP Authorization
HTTP Authorization
478 0
remote: Incorrect username or password ( access token ) fatal: Authentication failed for 'https:/...
remote: Incorrect username or password ( access token ) fatal: Authentication failed 开门见山—— 解决方法: 1.
5326 0

热门文章

最新文章