Autofac托管的WCF服务可在禁用匿名访问的情况下公开元数据

时间:2019-06-19 10:29:43

标签: wcf autofac wcf-binding

我们成功使用了autofac来托管我们的WCF服务。我们有一项服务需要我们公开其元数据,但是我们没有在IIS 7中启用匿名身份验证。在没有AutoFac的情况下可以正常工作。

在没有autofac的情况下,此方法可以很好地工作。一旦我们在service.svc文件中使用autofac主机工厂:

这是服务的服务模型组件:

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="httpEPBinding" sendTimeout="00:05:00">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="serviceBehaviors" name="WcfEngineAutofac.CalcEngine">
        <endpoint binding="basicHttpBinding" bindingConfiguration="httpEPBinding" name="HttpEP" contract="WcfEngineAutofac.ICalcEngine">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" name="mexHttpEP" contract="IMetadataExchange" listenUriMode="Explicit">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceBehaviors">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>

    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
  </system.serviceModel> 

在没有autofac的情况下,此方法可以很好地工作。一旦我们在service.svc文件中使用autofac主机工厂:

<%@ ServiceHost
Service="WcfEngineAutofac.ICalcEngine"
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf"     %>

我们收到以下错误:

The authentication schemes configured on the host ('IntegratedWindowsAuthentication') do not allow those configured on the binding 'BasicHttpBinding' ('Anonymous'). Please ensure that the SecurityMode is set to Transport or TransportCredentialOnly. Additionally, this may be resolved by changing the authentication schemes for this application through the IIS management tool, through the ServiceHost.Authentication.AuthenticationSchemes property, in the application configuration file at the <serviceAuthenticationManager> element, by updating the ClientCredentialType property on the binding, or by adjusting the AuthenticationScheme property on the HttpTransportBindingElement.

当我们在IIS中启用匿名身份验证和Windows身份验证时,错误消失了,但是我们不允许在生产环境中这样做!

任何想法!我喜欢autofac,但是如果我们解决不了,就不能使用它...

0 个答案:

没有答案