【问题标题】:WCF 4 REST - Multiple Standard Endpoints for AuthenticationWCF 4 REST - 用于身份验证的多个标准端点
【发布时间】:2011-11-10 18:53:58
【问题描述】:

所以我正在尝试配置 WCF 4 REST 应用程序以利用多个标准端点(用于帮助功能)。原因是我的托管 IIS 进程同时启用了匿名和 Windows 身份验证,并且我的 WCF 应用程序中的某些端点需要其中一个(两者都会导致异常)。

以前,我可以通过定义一些绑定来做到这一点:

<bindings>
  <webHttpBinding>
    <binding name="Anonymous">
      <security mode="None" />
    </binding>

    <binding name="WindowsAuthentication">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>

然后像这样定义服务:

<services>
  <service name="Host.SubscriberInfoHost">
    <endpoint address="" binding="webHttpBinding" bindingConfiguration="WindowsAuthentication" contract="Host.ISubscriberInfoHost" />
  </service>
  <service name="Utilities.Instrumentation.ServiceStatus.ServiceStatusHost">
    <endpoint address="" binding="webHttpBinding" bindingConfiguration="Anonymous" contract="Utilities.Instrumentation.ServiceStatus.IServiceStatusHost" />
  </service>
</services>

这是我迄今为止在使用标准端点模型时尝试做的事情:

    <standardEndpoints>
        <webHttpEndpoint>
            <standardEndpoint name="Host.SubscriberInfoHost" helpEnabled="true" automaticFormatSelectionEnabled="true">
              <security mode="TransportCredentialOnly">
                <transport clientCredentialType="Windows" />
              </security>
             </standardEndpoint>

            <standardEndpoint name="Utilities.Instrumentation.ServiceStatus.IServiceStatusHost" helpEnabled="true" automaticFormatSelectionEnabled="true">
              <security mode="None" />
            </standardEndpoint>
        </webHttpEndpoint>
    </standardEndpoints>

但是,这样做会使服务感到困惑,因为我收到了:

System.InvalidOperationException: IIS specified authentication schemes 'Negotiate, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used

这正是我想要摆脱的。任何人都可以帮助我如何使用新的标准端点模型来设置这种情况吗?谢谢!

【问题讨论】:

    标签: c# wcf rest windows-authentication


    【解决方案1】:

    经过一些实验后找到了答案。事实证明,标准端点的“名称”属性实际上是一个端点配置。因此,您将使用以下标准端点:

    <standardEndpoint name="WindowsAuthentication" helpEnabled="true" automaticFormatSelectionEnabled="true"> 
              <security mode="TransportCredentialOnly"> 
                <transport clientCredentialType="Windows" /> 
              </security> 
     </standardEndpoint> 
    
     <standardEndpoint name="Anonymous" helpEnabled="true" automaticFormatSelectionEnabled="true"> 
              <security mode="None" /> 
     </standardEndpoint> 
    

    然后,您还需要配置如下服务(必须设置“kind”和“endpointConfiguration”属性才能将此端点绑定到上面的标准端点)

      <service name="SomeEndpoint">
        <endpoint address="" kind="webHttpEndpoint" endpointConfiguration="WindowsAuthentication" contract="ISomeEndpoint" />
      </service>
    

    这允许您混合身份验证样式,同时维护方便的服务帮助页面。

    【讨论】:

    • 据我所知,一项服务只能使用一种认证方式。这行得通吗?
    • 这确实对我有用,请注意这是很久以前的事了,我相信 .NET 3.5
    • @PaulKirby.. 你能帮我吗...stackoverflow.com/questions/54542109/…
    • 我试过这个..没有成功..你有 WindowsAuthentication 作为绑定名称和标准端点名称..这让我很困惑......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    • 1970-01-01
    • 2011-03-27
    • 1970-01-01
    • 2019-08-20
    • 2019-07-24
    • 2012-03-06
    相关资源
    最近更新 更多