【问题标题】:IIS hosted WCF-service + Windows auth in IIS + TransportCredentialOnly/Windows auth in basicHttpBindingIIS 托管 WCF 服务 + Windows 身份验证在 IIS + TransportCredentialOnly/Windows 身份验证在 basicHttpBinding
【发布时间】:2008-10-20 16:58:23
【问题描述】:

我想创建一个托管在 IIS6 中的 WCF 服务并在 IIS 中禁用匿名身份验证。并且不要使用 SSL。

所以我唯一的办法就是使用带有TransportCredentialOnly 的basicHttpBinging,不是吗?

我创建一个虚拟目录,设置 Windows 集成身份验证并取消选中“启用匿名访问”。

这是我的 web.config:

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="MyBinding">
                    <security mode="TransportCredentialOnly">
                        <transport clientCredentialType="Windows" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <services>
            <service name="Samples.ServiceFacadeService" behaviorConfiguration="ServiceFacadeServiceBehavior">
                <endpoint address="" binding="basicHttpBinding" bindingName="MyBinding"
                          contract="Samples.IServiceFacadeService">
                </endpoint>
            </service>
        </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceFacadeServiceBehavior">
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

您可以看到,我什至没有包含用于元数据交换的 MEX-enpoint。只有一个端点和一个具有 TransportCredentialOnly 安全性的绑定。

但是当我尝试启动服务(通过客户端代理调用方法)时,我在 EventLog 中遇到了这样的异常:

例外: System.ServiceModel.ServiceActivationException: 服务 '/wcftest/ServiceFacadeService.svc' 无法激活,因为 编译时出现异常。这 异常消息是:安全 此服务的设置需要 “匿名”身份验证,但它是 未为 IIS 应用程序启用 托管此服务.. ---> System.NotSupportedException:安全性 此服务的设置需要 “匿名”身份验证,但它是 未为 IIS 应用程序启用 托管此服务。

我不知道为什么我的服务需要匿名身份验证?为什么?

【问题讨论】:

    标签: wcf iis


    【解决方案1】:

    答案找到了jezell。谢谢。 我混淆了 bindingName 和 bindingConfiguration :

    <endpoint address="" binding="basicHttpBinding" bindingName="MyBinding"
              contract="Samples.IServiceFacadeService">
    </endpoint>
    

    没错:

    <endpoint address="" binding="basicHttpBinding" **bindingConfiguration**="MyBinding"
              contract="Samples.IServiceFacadeService">
    </endpoint>
    

    【讨论】:

      【解决方案2】:

      MEX 端点可能仍然是问题所在(请参阅此post)。尝试像这样禁用 MEX:

      <services>
          <!-- Note: the service name must match the configuration name for the service implementation. -->
          <service name="MyNamespace.MyServiceType" behaviorConfiguration="MyServiceTypeBehaviors" >
              <!-- Add the following endpoint.  -->
              <!-- Note: your service must have an http base address to add this endpoint. -->
              <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
          </service>
      </services>
      
      <behaviors>
          <serviceBehaviors>
              <behavior name="MyServiceTypeBehaviors" >
                  <!-- This disables it. -->
                  <serviceMetadata httpGetEnabled="false" />
              </behavior>
          </serviceBehaviors>
      </behaviors>
      

      这是一个很好的 post 保护 MEX。

      【讨论】:

      • 我根本没有 MEX 端点。保护 mex-endpoint 是另一个挑战。但我同意根本不拥有它。如果我没有 mex-endpoint,我想将 httpGetEnabled 设置为 false 是没有意义的。无论如何,这没有帮助,我试过了。
      • 我认为 WCF 会自动设置默认的 MEX 端点。我提出的建议是手动创建覆盖默认值的 MEX 端点并禁用它,以防止编译步骤检测到对 MEX 端点具有匿名访问权限的要求。
      • 有趣。但是在我修复了我的愚蠢错误之后,一切都在没有 mex-endpoint 的情况下正常工作。
      【解决方案3】:

      对你的 mex 端点使用 basicHttpBinding 并应用相同的 bindingConfiguration:

      【讨论】:

        【解决方案4】:

        要让 VS wcf 服务项目(新示例项目)在 IIS 下使用身份验证,您必须:

        1) 在 IIS 中允许匿名访问
        2) 在你的公共方法前加上这样的属性:

        [PrincipalPermission(SecurityAction.Demand, Role = "MyADGroup")]
        public string SendMyMessage(string Message)
        {...}
        

        【讨论】:

          猜你喜欢
          • 2011-07-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-02-17
          • 2011-06-13
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多