客户端身份验证方案“匿名”禁止HTTP请求。返回403

时间:2020-02-18 09:16:19

标签: wcf

调用服务“在客户端身份验证方案'Anonymous'禁止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>

1 个答案:

答案 0 :(得分:0)

当服务器通过证书对客户端进行身份验证时,通常会发生此错误,而与当前方案无关。如果未在客户端和服务器之间建立证书的信任关系,则会发生此错误。
我怀疑是否使用上述服务器配置自动生成了客户端配置。在上述配置中,我们应该在服务器端的网站上添加一个https绑定,以使Basichttpbinding具有传输安全模式。在客户端,我们应该在调用服务之前信任服务器证书,否则我们将收到以下类似错误。

“基础连接已关闭:无法建立信任关系 SSL / TLS安全通道”。

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

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

我想了解有关错误发生方式的更多详细信息。随时让我知道是否有什么可以帮助您的。