IIS托管的WCF服务+ IIS中的Windows身份验证+ basicHttpBinding中的TransportCredentialOnly / Windows身份验证

22

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

那么我唯一的选择是使用带有TransportCredentialOnly的basicHttpBinging,对吗?

我创建了一个虚拟目录,设置了Windows Integrated Auth并取消选中"启用匿名访问"。

这是我的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端点。只有一个端点和一个带有TransportCredentialOnly安全性的绑定。

但是当我尝试启动服务(通过客户端代理调用方法)时,在事件日志中出现了这样的异常:

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

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

4个回答

8
答案在jezell找到了。谢谢。 我混淆了bindingName和bindingConfiguration:
<endpoint address="" binding="basicHttpBinding" bindingName="MyBinding"
          contract="Samples.IServiceFacadeService">
</endpoint>

没错:

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

7

MEX端点可能仍然是问题所在(请参阅此文章)。尝试像这样禁用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>

这里有一篇关于保护MEX的好文章(链接)


我根本没有MEX端点。保护mex端点是另一个挑战。但我同意根本不需要它。如果我没有mex端点,将httpGetEnabled设置为false就没有意义了。无论如何,这并没有帮助我,我已经尝试过了。 - Shrike
我认为WCF会自动设置一个默认的MEX终结点。我提出的建议是手动创建MEX终结点,覆盖默认设置并禁用它,以防止编译步骤检测到MEX终结点需要匿名访问的要求。 - Sixto Saez
有趣。但在我修复了愚蠢的错误之后,所有东西都能够正常工作,而不需要 mex-endpoint。 - Shrike

3
使用basicHttpBinding作为mex终结点,并应用相同的bindingConfiguration:

1

要使VS WCF服务项目(新示例项目)在IIS下进行身份验证,您需要:

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接