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

 

目录
相关文章
|
15天前
|
弹性计算 安全 API
HTTP 405 Method Not Allowed:解析与解决
本文详细解析了HTTP 405 &quot;Method Not Allowed&quot; 错误,包括其定义、常见原因、示例代码及解决方案。通过检查API文档、修改请求方法或更新服务器配置,可有效解决此错误,提升Web开发效率。
|
1月前
|
安全 应用服务中间件 网络安全
修复HTTPS升级后出现 Mixed Content: The page at 'https://xxx' was loaded over HTTPS, but requested an insecure frame 'http://xxx'. This request has been blocked; the content must be served over HTTPS. 的问题
修复HTTPS升级后出现 Mixed Content: The page at 'https://xxx' was loaded over HTTPS, but requested an insecure frame 'http://xxx'. This request has been blocked; the content must be served over HTTPS. 的问题
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
4299 0
|
5月前
|
前端开发 对象存储 数据安全/隐私保护
阿里云前端直传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
630 2
|
4月前
|
API Java
解决HTTP 400 Bad Request错误的方法
解决HTTP 400 Bad Request错误的方法
|
6月前
|
应用服务中间件 网络安全 nginx
Client sent an HTTP request to an HTTPS server
Client sent an HTTP request to an HTTPS server
874 0
|
6月前
|
Java 应用服务中间件
HTTP Status 404(The requested resource is not available)
HTTP Status 404(The requested resource is not available)
43 0
|
开发工具 数据安全/隐私保护
The request you have made requires authentication. (HTTP 401)
The request you have made requires authentication. (HTTP 401)
1345 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.
1205 0
|
Web App开发 应用服务中间件
tomcat报错:Error parsing HTTP request header
tomcat报错:Error parsing HTTP request header
342 0