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;
}

 

时间: 2024-09-15 05:30:05

HTTP request is unauthorized with client authentication scheme 'Anonymous'.的相关文章

spring mvc 数据绑定问题 提交表单提示HTTP status 400, The request sent by the client was syntactically incorrect

我们在spring mvc 中controller方法中的参数,spring mvc会自动为我们进行数据绑定. spring mvc 方法中不一定要全部都有 form表单提交的属性, 也可以有 请求属性中 没有的参数(这时候只会把对应不上的参数设为null),这两种情况都不会报错. 但是有几种情况会报错,可能会提示HTTP status 400,  The request sent by the client was syntactically incorrect,而且此时如果加断点你会发现根本

Http 400 --- The request sent by the client was syntactically incorrect

Http 400 --- The request sent by the client was syntactically incorrect         问题描述         "The request sent by the client was syntactically incorrect",意思是:客户端发送的请求是语法错误.         问题重现         原因及解决方法         其实这次错误写篇博客是完全没有意义的,因为笔者在下图中的两个参数写得不

POST 400 Bad Request The request sent by the client was syntactically incorrect

最近在做Web开发的时候,使用$.post提交数据,但是回调函数却没有被触发,按F12看控制台输出是:POST *** 400 Bad Request 后台是SpringMVC的,设置了断点也不会被触发. 后来查看JQuery资料了解到,$.post提交数据只有成功时才触发回调函数,于是改用$.ajax提交数据,添加error回调函数,得到错误信息了,如下图: 这个问题是什么原因造成的呢? 后来经过测试发现,是表单提交的内容数据类型与实体的(也就是数据表字段)的数据类型不匹配导致的. 在提交表单

wcf-WCF 身份验证问题,当服务器 上运行客户端程序时 会出现验证失败的结果

问题描述 WCF 身份验证问题,当服务器 上运行客户端程序时 会出现验证失败的结果 服务器端 身份验证设置的是 只启用Windows身份验证,设置好登录名,密码,域等信息, 现在一段测试程序连接WCF地址,访问密码.用户名.域都配置正确,配置文件设置验证如下: 在本机上运行,一切正常,能够访问数据库等等一切操作,但是如果将程序放到服务器上(这个服务器就是搭建WCF 的服务器),运行就会爆验证不通过的错,报错如下:System.ServiceModel.Security.MessageSecuri

分享:XML HTTP Request的属性和方法简介

由于现在在公司负责制作标准的静态页面,为了增强客户体验,所以经常要做些AJAX效果,也学你也和我一样在,学习AJAX.而设计AJAX时使用的一个重要的技术(工具)就是XMLHTTPRequest对象了.这里海啸把我学习XMLHTTPRequest对象的一点资料拿出来跟大家一起分享.文中的资料都是海啸在学习时在网上收集的,如果您开过,那就再加深下印象吧! 1.XMLHTTPRequest对象什么是? 最通用的定义为:XmlHttp是一套可以在Javascript.VbScript.Jscript等

Set Up Client Certificates

client How To: Set Up Client CertificatesJ.D. Meier, Alex Mackman, Michael Dunner, and Srinath VasireddyMicrosoft Corporation November 2002 Microsoft ASP.NET Microsoft Visual Studio .NET See the Landing Page for a starting point and complete overview

How to Send an HTTP Header With Every Request With Spring RestTemplate

  In Know Which Apps Are Hitting Your Web Service, I showed how to write a servlet filter that enforces the existence of a special HTTP request header. From a client perspective, it would be nice to send this header automatically, instead of having t

Request对象限制102,399 bytes..这样....

request|对象 When you post a large form field, you may receive the following error message: Error Type:Request object, ASP 0107 (0x80004005)The data being processed is over the allowed limit. In Microsoft Internet Information Server (IIS) 4.0, you may

TensorFlow教程之API DOC 6.3.2. CLIENT

本文档为TensorFlow参考文档,本转载已得到TensorFlow中文社区授权. Running Graphs Contents Running Graphs Session management class tf.Session class tf.InteractiveSession tf.get_default_session() Error classes class tf.OpError class tf.errors.CancelledError class tf.errors.U