模拟在特定域帐户下运行的WCF服务(在IIS上托管)

时间:2014-01-31 23:33:23

标签: wcf impersonation

我希望我的WCF服务是IIS服务器上的主机,应该模拟特定的域帐户。 如果是普通网站,我使用下面的代码来冒充特定的域帐户:

<system.web>
  <!-- ASP.NET runs as the specified user -->
  <identity impersonate="true"
            userName="DOMAIN\user"
            password="password" />
</system.web>

我需要一些类似的方法,我可以在我的WCF服务web.config文件中使用它来模拟特定的域帐户,以便所有WCF的操作都在此帐户下运行。

1 个答案:

答案 0 :(得分:1)

我不知道是否是一种好方法,但我使用以下步骤来解决我的问题。

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="True">
    </serviceHostingEnvironment>
    <services>
      <service name="Service" behaviorConfiguration="ServiceBehavior">
        <endpoint address="" binding="basicHttpBinding" contract="IService">
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          ........some othere setting
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

在system.web下添加I我使用以下代码

<system.web>
   <authorization>
        <allow users="?"/>
      </authorization>
  <identity impersonate="true" userName="DOMAIN\user" password="password" />
</system.web> 
在Service.vb上的

我添加了

<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Required)> _
Public Class Service Implements IService