【问题标题】:The HTTP request was forbidden with client authentication scheme 'Anonymous'. returning 403客户端身份验证方案“匿名”禁止 HTTP 请求。返回 403
【发布时间】:2020-02-18 09:16:19
【问题描述】:

调用服务时出现错误“客户端身份验证方案‘匿名’禁止 HTTP 请求。”

实际上我在 plesk 中托管此服务,并且在 plesk 中启用了匿名身份验证。

WCF 配置

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="SampleService.ServiceContracts.SampleService" behaviorConfiguration="mexBehaviour">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpConfig" contract="SampleService.ServiceContracts.ISampleService"></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpConfig" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" receiveTimeout="00:00:10">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehaviour">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true"></serviceDebug>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpBinding" scheme="https"  />
    </protocolMapping>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

客户

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ISampleService">
          <security mode="Transport" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://samplewcf.packletsgo.com/ServiceContracts/SampleService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleService"
        contract="ServiceReference1.ISampleService" name="BasicHttpBinding_ISampleService" />
    </client>
  </system.serviceModel>

【问题讨论】:

    标签: wcf


    【解决方案1】:

    此错误通常发生在服务器使用证书对客户端进行身份验证时,与您当前的情况无关。如果客户端和服务器之间没有建立证书的信任关系,就会出现这个错误。
    我怀疑客户端配置是否是使用上面的服务器配置自动生成的。在上面的配置中,我们应该在服务器端添加一个 https 绑定到网站,以适应 Basichttpbinding 的传输安全模式。在客户端,我们应该在调用服务之前信任服务器证书,否则我们会得到下面类似的错误。

    “底层连接关闭:无法建立信任 SSL/TLS 安全通道”。

    简而言之,我们需要在与服务器通信之前验证远程证书是否有效。
    最后,为什么服务包含以下片段,你使用虚拟路径吗?

    https://localhost/SampleService/AuthService/AuthService.svc

    我想了解有关错误是如何发生的更多详细信息。如果有什么可以帮助的,请随时告诉我。

    【讨论】:

    • samplewcf.packletsgo.com/ServiceContracts/SampleService.svc 这是我的示例服务,您可以使用您的客户端查看。
    • 我在问题中编辑了新的客户端和服务器网络配置,感谢您的评论。
    • @ManiLancer,这应该是防火墙/杀毒软件的问题。在我这边,我尝试重现您的问题,而客户端工作正常(在信任服务器证书之后)。请检查网络设置,看看我们的IP是否在黑名单中。
    • 没有黑名单IP,可以调用服务方法吗??
    • 我没有骗你,我可以正常调用service方法。可以在内网局域网内的两台机器上测试。
    猜你喜欢
    • 1970-01-01
    • 2011-03-01
    • 2014-07-22
    • 2011-12-11
    • 2016-02-04
    • 1970-01-01
    • 2014-11-27
    • 2020-04-05
    相关资源
    最近更新 更多