【问题标题】:WCF Service ImpersonationWCF 服务模拟
【发布时间】:2011-02-10 06:10:50
【问题描述】:

大家好...

显然,我没有为我的 WCF 服务正确设置模拟。我不想逐个方法设置安全性(在实际的代码隐藏中)。该服务(目前)对外开放,可供内网上的每个人调用。

所以我的问题是……

问:我缺少哪些 web-config 标签?

问:我需要在网络配置中进行哪些更改才能使模拟工作?

服务 Web.config 看起来像...

<configuration>
    <system.web>
        <authorization>
            <allow users="?"/>
        </authorization>
        <authentication mode="Windows"/>
        <identity impersonate="true" userName="MyDomain\MyUser" password="MyPassword"/>
    </system.web>
    <system.serviceModel>
        <services>
            <service behaviorConfiguration="wcfFISH.DataServiceBehavior" name="wcfFISH.DataService">
                    <endpoint address="" binding="wsHttpBinding" contract="wcfFISH.IFishData">
                    <identity>
                        <dns value="localhost"/>
                    </identity>
                </endpoint>
                    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                </service>
            </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="wcfFISH.DataServiceBehavior">
                    <serviceMetadata httpGetEnabled="false"/>
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

【问题讨论】:

    标签: wcf wcf-security


    【解决方案1】:

    如果您总是想模拟客户端,对于所有操作,请将以下内容添加到 &lt;behavior&gt; 元素,即在 &lt;serviceMetadata&gt; 元素之后:

    <serviceAuthorization impersonateCallerForAllOperations="true" />
    

    如果您尝试在 应用程序 级别进行模拟,那么您通常无法在 WCF 中执行此操作,因为 WCF 并不是真正的 ASP.NET 管道的一部分。

    最简单的解决方法是将 WCF 应用程序放入其自己的应用程序池中,并将池的进程标识设置为您要模拟的用户。

    另一种方式是开启ASP.NET兼容模式,将这个添加到&lt;system.servicemodel&gt;

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    

    您有时还需要用以下方式装饰您的服务:

    [AspNetCompatibilityRequirements(
        RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    

    但请记住,这将限制您利用许多其他较新的 WCF 功能(如 MSMQ 或 TCP 绑定)的能力。我更喜欢隔离的应用程序池方法。

    【讨论】:

    • 我不想冒充客户。我希望服务连接到数据库。出于某种原因……它不会。 LOGIN & PASSWORD 是正确的...但服务不会接受身份。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多