Impersonate WCF service to run under a specific Domain Account(Hosted on IIS)

只愿长相守 提交于 2019-12-13 04:42:37

问题


I want my WCF service which is host on IIS server should impersonate to a specific Domain Account. In case of a normal website I am using below code to impersonate to specific domain account :

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

I need something similar approach which I can use in my WCF service web.config file to impersonate to a specific domain account so that all WCF's operation will run under this account.


回答1:


I don't know whether is a good approach or not, however I used the following steps to resolve my issue.

<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>

Add I under the system.web I use the following code

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

on Service.vb class I added

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


来源:https://stackoverflow.com/questions/21492023/impersonate-wcf-service-to-run-under-a-specific-domain-accounthosted-on-iis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!