WCF - Windows 身份验证 - 安全设置需要匿名

问题描述:

我正在努力让 WCF 服务在我们服务器上的 IIS 上运行.部署后,我最终收到一条错误消息:

I am struggling hard with getting WCF service running on IIS on our server. After deployment I end up with an error message:

此服务的安全设置需要匿名"身份验证,但未为托管此服务的 IIS 应用程序启用.

我想使用 Windows 身份验证,因此我禁用了匿名访问.另请注意,有 aspNetCompatibilityEnabled(如果有任何区别).

I want to use Windows authentication and thus I have Anonymous access disabled. Also note that there is aspNetCompatibilityEnabled (if that makes any difference).

这是我的 web.config:

Here's my web.config:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <bindings>
        <webHttpBinding>
            <binding name="default">
                <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Windows" proxyCredentialType="Windows"/>
                </security>
            </binding>
        </webHttpBinding>
    </bindings>
    <behaviors>
        <endpointBehaviors>
            <behavior name="AspNetAjaxBehavior">
                <enableWebScript />
                <webHttp />
            </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
            <behavior name="defaultServiceBehavior">
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
                <serviceDebug includeExceptionDetailInFaults="true" />
                <serviceAuthorization principalPermissionMode="UseWindowsGroups" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service name="xxx.Web.Services.RequestService" behaviorConfiguration="defaultServiceBehavior">
            <endpoint behaviorConfiguration="AspNetAjaxBehavior" binding="webHttpBinding"
             contract="xxx.Web.Services.IRequestService" bindingConfiguration="default">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"></endpoint>
        </service>
    </services>
</system.serviceModel>

我在互联网上搜索了所有内容,但都没有运气.任何线索都非常感谢.

I have searched all over the internet with no luck. Any clues are greatly appreciated.

所以这似乎是很常见的问题.关键是从绑定中删除 mex:

So it seems like pretty common issue. The point is to remove mex from your bindings:

<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"></endpoint>

或者,您可以在 IIS 和 web.config 中启用匿名访问,确保拒绝匿名访问.

Alternativelly you enable Anonymous access in IIS and in your web.config you make sure anonymous access is denied.

希望这能帮助其他一些人.(我 100% 确定我在删除了 mex 的情况下尝试了它.:-O )

Hope this will help some other soul. (I was 100% sure I tried it with mex removed. :-O )