情况:WCF服务在浏览器中可以正常浏览,但是通过程序调用提示:

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

详细错误信息:

  1. 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.
  2. at System.Net.HttpWebRequest.GetResponse()
  3. at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

解决方法(以匿名访问):

1.检查当前服务的身份验证模式是否和WCF在config中配置的模式是否一致。例如:

  1. <binding name="BasicHttpBinding_Service" closeTimeout="00:00:30"
  2. openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
  3. bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
  4. maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
  5. useDefaultWebProxy="true" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
  6. allowCookies="false">
  7. <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
  8. maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
  9. <security mode="None">
  10. <transport clientCredentialType="None" />
  11. <message clientCredentialType="UserName"/>
  12. </security>
  13. </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

  1. 代码
  2.  
  3. <?xml version="1.0" encoding="utf-8"?>
  4. <configuration>
  5. <system.serviceModel>
  6. <bindings>
  7. <basicHttpBinding>
  8. <binding name="BasicHttpBinding_BusinessDataCatalogSharedService"
  9. closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
  10. sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false"
  11. hostNameComparisonMode="StrongWildcard" maxBufferSize="999999"
  12. maxBufferPoolSize="9999999" maxReceivedMessageSize="999999"
  13. messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered"
  14. useDefaultWebProxy="true">
  15. <readerQuotas maxDepth="99" maxStringContentLength="999999" maxArrayLength="999999"
  16. maxBytesPerRead="999999" maxNameTableCharCount="999999" />
  17. <security mode="TransportCredentialOnly">
  18. <transport clientCredentialType="Ntlm" proxyCredentialType="None"
  19. realm="">
  20. <extendedProtectionPolicy policyEnforcement="Never" />
  21. </transport>
  22. <message clientCredentialType="UserName" algorithmSuite="Default" />
  23. </security>
  24. </binding>
  25. <binding name="BasicHttpBinding_BusinessDataCatalogSharedService1"
  26. closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
  27. sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false"
  28. hostNameComparisonMode="StrongWildcard" maxBufferSize="999999"
  29. maxBufferPoolSize="9999999" maxReceivedMessageSize="999999"
  30. messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered"
  31. useDefaultWebProxy="true">
  32. <readerQuotas maxDepth="99" maxStringContentLength="999999" maxArrayLength="999999"
  33. maxBytesPerRead="999999" maxNameTableCharCount="999999" />
  34. <security mode="Transport">
  35. <transport clientCredentialType="Ntlm" proxyCredentialType="None"
  36. realm="">
  37. <!--<extendedProtectionPolicy policyEnforcement="Never" />-->
  38. </transport>
  39. <message clientCredentialType="UserName" algorithmSuite="Default" />
  40. </security>
  41. </binding>
  42. </basicHttpBinding>
  43. </bindings>
  44. <client>
  45. <endpoint address="http://SUT02/_vti_bin/BdcAdminService.svc"
  46. binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_BusinessDataCatalogSharedService"
  47. contract="BusinessDataCatalogSharedService" name="BasicHttpBinding_BusinessDataCatalogSharedService" />
  48. <endpoint address="https://SUT02:443/_vti_bin/BdcAdminService.svc"
  49. binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_BusinessDataCatalogSharedService1"
  50. contract="BusinessDataCatalogSharedService" name="BasicHttpBinding_BusinessDataCatalogSharedService1" />
  51. </client>
  52. </system.serviceModel>
  53. </configuration>

client端的代码如下:

  1. 代码
  2.  
  3. static void Main(string[] args)
  4. {
  5. BusinessDataCatalogSharedServiceClient client = new BusinessDataCatalogSharedServiceClient("BasicHttpBinding_BusinessDataCatalogSharedService1");
  6. client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
  7. client.ClientCredentials.UserName.UserName = @"domain\userName";
  8. client.ClientCredentials.UserName.Password = "Password";
  9. client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("username", "Password", "domain");
  10. AcceptAllCertificate();
  11. try
  12. {
  13. Guid guid = client.GetServiceApplicationId();
  14. }
  15. catch (Exception ex)
  16. {
  17. throw;
  18. }
  19.  
  20. }
  21.  
  22. /// <summary>
  23. /// Case request Url include HTTPS and TCP prefix, use this function to avoid closing base connection.
  24. /// Local client will accept all certificate after execute this function.
  25. /// </summary>
  26. public static void AcceptAllCertificate()
  27. {
  28. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
  29. }
  30. /// <summary>
  31. /// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication.
  32. /// In our adapter,we make this method always return true, make client can communicate with server under HTTPS without a certification.
  33. /// </summary>
  34. /// <param name="sender">An object that contains state information for this validation.</param>
  35. /// <param name="certificate">The certificate used to authenticate the remote party.</param>
  36. /// <param name="chain">The chain of certificate authorities associated with the remote certificate.</param>
  37. /// <param name="sslPolicyErrors">One or more errors associated with the remote certificate.</param>
  38. /// <returns>A Boolean value that determines whether the specified certificate is accepted for authentication.</returns>
  39. private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
  40. {
  41. return true;
  42. }

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

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

  1. <system.serviceModel>
  2. <bindings>
  3. <basicHttpBinding>
  4. <binding>
  5.  
  6. <readerQuotas/>
  7. <security mode="TransportCredentialOnly">
  8. <transport clientCredentialType="Windows" proxyCredentialType="Windows" realm="" />
  9. <message clientCredentialType="UserName" algorithmSuite="Default" />
  10. </security>
  11. </binding>
  12. </basicHttpBinding>
  13. </bindings>
  14.  
  15. <client>
  16. <endpoint ... behaviorConfiguration="ImpersonationBehavior"/>
  17. </client>
  18.  
  19. <behaviors>
  20. <endpointBehaviors>
  21. <behavior name="ImpersonationBehavior">
  22. <clientCredentials>
  23. <windows allowedImpersonationLevel="Impersonation"/>
  24. </clientCredentials>
  25. </behavior>
  26. </endpointBehaviors>
  27. </behaviors>
  28.  
  29. </system.serviceModel>

HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'。的更多相关文章

  1. SpringMVC报错The request sent by the client was syntactically incorrect ()

    springmvc数据绑定出的错 在数据绑定的时候一定要主意Controller方法中的参数名和jsp页面里的参数名字是否一致或者按照绑定的规范来写, 如果不一致,可能回报如下错误: The requ ...

  2. "The request sent by the client was syntactically incorrect ()"问题定位及解决:

    Spring MVC "The request sent by the client was syntactically incorrect ()"解决办法: 把spring日志级 ...

  3. The request sent by the client was syntactically incorrect问题解决

    The request sent by the client was syntactically incorrect意思嘛,google翻译一下 通过日志不难看出,是由参数不匹配造成的. 所以对于Da ...

  4. 错误:The request sent by the client was syntactically incorrect的解决

    问题: 错误400-The request sent by the client was syntactically incorrect. springMVC中,某个页面提交时报400错误,如下图. ...

  5. spring mvc 在上传图片时,浏览器报The request sent by the client was syntactically incorrect

    项目中,在一个jsp页面里其它图片上传是功能是可以使用的,当我自己新加了一个图片上传时,提交表单后,浏览器报The request sent by the client was syntactical ...

  6. SpringMVC---400错误The request sent by the client was syntactically incorrect ()

    在SpringMVC中使用@RequestBody和@ModelAttribute注解时遇到了很多问题,现记录下来. @ModelAttribute这个注解主要是将客户端请求的参数绑定参数到一个对象上 ...

  7. 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 ...

  8. 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 ...

  9. 又见The request sent by the client was syntactically incorrect ()

    前几天遇到过这个问题(Ref:http://www.cnblogs.com/xiandedanteng/p/4168609.html),问题在页面的组件name和和注解的@param名匹配不对,这个好 ...

随机推荐

  1. java Web监听器导图详解

    监听器是JAVA Web开发中很重要的内容,其中涉及到的知识,可以参考下面导图: Web监听器 1 什么是web监听器? web监听器是一种Servlet中的特殊的类,它们能帮助开发者监听web中的特 ...

  2. windows下安装配置apacheserver

    注:一開始公布的时候 图片是复制粘贴的.所以公布完图片所有消失了...如今是补发图片. . .2016/04/25 1.进入apache官网  http://httpd.apache.org/ 这里我 ...

  3. 面向对象设计原则一:单一职责原则(SRP)

    单一职责原则(SRP) 定义:系统中的每一个类都应该只有一个职责. 好处:高内聚.低耦合. 解释说明: 单一职责也就是说我们应该让一个类或一个对象只做一件事情,每个类所要关注的就是自己要完成的职责是什 ...

  4. LigerUI 树状列表折叠显示

    http://blog.csdn.net/haojuntu/article/details/8626040 —————————————————————————————————————————————— ...

  5. jQuery开发中容易忽视的错误

    1.引用jQuery库文件的<script>标签,必须放在引用自定义脚本文件的<script>标签之前,否则,就会发生找不到对象:最好在<head>元素中,把引入样 ...

  6. JAVA面试-HIBERNATE与 MYBATIS的对比

    JAVA面试中问及HIBERNATE与 MYBATIS的对比,在这里做一下总结   我是一名java开发人员,hibernate以及mybatis都有过学习,在java面试中也被提及问道过,在项目实践 ...

  7. 28Mybatis_查询缓存-二级缓存-二级缓存测试-

    二级缓存原理:

  8. nginx php文件上传的大小配置问题

  9. jboss eap 6.4 部署 从weblogic迁移

    从weblogic10.3像jboss 6.4项目迁移,遇到的一些问题: 因为使用weblogic可以自定义公共的war包库,在使用jboss中,也采取项目依赖公共库的方式: 1.jboss中使用公共 ...

  10. Apache里的httpd-vhosts.conf详解

    首先看下面的配置: <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "D ...