HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'。
情况:WCF服务在浏览器中可以正常浏览,但是通过程序调用提示:
HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'
。
详细错误信息:
System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'. ---> System.Net.WebException: The remote server returned an error: () Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
解决方法(以匿名访问):
1.检查当前服务的身份验证模式是否和WCF在config中配置的模式是否一致。例如:
<binding name="BasicHttpBinding_Service" closeTimeout="00:00:30"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
useDefaultWebProxy="true" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName"/>
</security>
</binding>
加密模式为None。那么就应该检查是IIS中该服务身份验证模式否开启了【匿名访问】。
2.确认【我的电脑】-右键-【管理】-【本地用户和组】-【用户】中是否存在IIS中匿名访问所设置的用户。
XP:默认为用户名称。默认用户名格式:IUSER_计算机名。如果没有该计算机名称,那么需要添加该用户。确保该用户未被禁用。
Win7:默认为用户类型。默认的用户类型为:IUSER
以上为我的实际解决方法。
以下为网上提供的其他 的解决方法:
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;
}
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'.
解决方案
1 配置IIS
网站->属性->目录安全性->身份验证方法: 同时选中”匿名访问”和”集成Windows身份验证”
2 配置WCF客户端的Config文件: 有3处地方: 1)security mode, 2)end point的behaviorConfiguration, 3)behaviors
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding …> <readerQuotas … />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="Windows" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings> <client>
<endpoint ... behaviorConfiguration="ImpersonationBehavior"/>
</client> <behaviors>
<endpointBehaviors>
<behavior name="ImpersonationBehavior">
<clientCredentials>
<windows allowedImpersonationLevel="Impersonation"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors> </system.serviceModel>
HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'。的更多相关文章
- SpringMVC报错The request sent by the client was syntactically incorrect ()
springmvc数据绑定出的错 在数据绑定的时候一定要主意Controller方法中的参数名和jsp页面里的参数名字是否一致或者按照绑定的规范来写, 如果不一致,可能回报如下错误: The requ ...
- "The request sent by the client was syntactically incorrect ()"问题定位及解决:
Spring MVC "The request sent by the client was syntactically incorrect ()"解决办法: 把spring日志级 ...
- The request sent by the client was syntactically incorrect问题解决
The request sent by the client was syntactically incorrect意思嘛,google翻译一下 通过日志不难看出,是由参数不匹配造成的. 所以对于Da ...
- 错误:The request sent by the client was syntactically incorrect的解决
问题: 错误400-The request sent by the client was syntactically incorrect. springMVC中,某个页面提交时报400错误,如下图. ...
- spring mvc 在上传图片时,浏览器报The request sent by the client was syntactically incorrect
项目中,在一个jsp页面里其它图片上传是功能是可以使用的,当我自己新加了一个图片上传时,提交表单后,浏览器报The request sent by the client was syntactical ...
- SpringMVC---400错误The request sent by the client was syntactically incorrect ()
在SpringMVC中使用@RequestBody和@ModelAttribute注解时遇到了很多问题,现记录下来. @ModelAttribute这个注解主要是将客户端请求的参数绑定参数到一个对象上 ...
- HTTP Status 400 - description The request sent by the client was syntactically incorrect.
HTTP Status 400 - type Status report message description The request sent by the client was syntacti ...
- The request sent by the client was syntactically incorrect.
HTTP Status 400 - type Status report message description The request sent by the client was syntacti ...
- 又见The request sent by the client was syntactically incorrect ()
前几天遇到过这个问题(Ref:http://www.cnblogs.com/xiandedanteng/p/4168609.html),问题在页面的组件name和和注解的@param名匹配不对,这个好 ...
随机推荐
- HttpURLConnection的使用
import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; ...
- [i.MX6q]i.MX6q处理器,linux操作系统平台搭建 从SD卡启动系统
转自:http://www.07net01.com/linux/2016/02/1232094.html 参照1:http://blog.csdn.net/girlkoo/article/detail ...
- exit会结束一个进程
#include <stdio.h> #include <unistd.h> #include <sys/types.h> #include<stdlib.h ...
- 如意云路由刷PandoraBox
目录 1 准备固件 2 使用uboot刷机 2.1 修改IP 2.2 开始刷写 3 ssh登录 4 刷回如意云 准备固件 http://downloads.openwrt.org.cn/Pandora ...
- CI框架中 类名不能以方法名相同
昨天晚上一个坑爹的问题折腾了我一晚上,首先我来说下我的代码,我建立了一个index的控制器然后呢 在控制器里有一个index的方法.页面模板都有. if ( ! defined('BASEPATH' ...
- serv-u ftp服务器搭建
以前在学校的时候,学校的整个宿舍楼都是在一个局域网中,经常有人用个人电脑搭个网站或者FTP啊什么的,主要是进行一些影视资源的传播活动.不乏有些资源充沛的有志青年利用业余时间翻译某岛国影视资源,利用局域 ...
- 关于Java中的HashMap的深浅拷贝的测试与几点思考
0.前言 工作忙起来后,许久不看算法,竟然DFA敏感词算法都要看好一阵才能理解...真是和三阶魔方还原手法一样,田园将芜,非常可惜啊. 在DFA算法中,第一步是需要理解它的数据结构,在此基础上,涉及到 ...
- ztree获取选中节点时不能进入可视区域出现BUG如何解决
zTree 是一个依靠 jQuery 实现的多功能 “树插件”.优异的性能.灵活的配置.多种功能的组合是 zTree 最大优点. zTree 的特点编辑 ● zTree v3.0 将核心代码按照功能进 ...
- 使用ADO GetChunk/AppendChunk 数据库存取二进制文件图象
在设计数据库的过程中,我们会经常要存储一些图形.长文本.多媒体(视频.音频文件)等各种各样的程序文件,如果我们在数据库中仅存储这些文件的路径信息,尽管这可以大大地减小数据库的大小,但是由于文件存在磁盘 ...
- 图像,script,link 空地址带来的困惑
前端开发人员估计很多人都不清楚这些标签的空地址会带来哪些让人意想不到的问题.包括我,很长一段时间都认为这是无伤大雅的事情,直到有一次遇到莫名其妙的问题,下面会拿image来详细介绍(其他类似). 下面 ...