0

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.

Yogi
  • 233
  • 5
  • 19
  • 1
    You could run the service in a separate app pool and have that app pool run under the domain service account. That might get you to where you want to be. – Tim Feb 01 '14 at 06:27
  • Hi Tim, Thanks for taking time to view my problem. as per IT guidelines I need to follow the save way as it is exist for other web sites in the IIS. we cann't define specific domain account for app pool. – Yogi Feb 03 '14 at 09:21
  • 1
    There doesn't appear to be a straight-forward way to do this in the config file (based on a quick search), but there are a number of options on MSDN - [Delegation and Impersonation with WCF](http://msdn.microsoft.com/en-us/library/ms730088(v=vs.110).aspx) - this might help (though using the App Pool and running it under a domain account would be a lot easier and more secure, IMO). – Tim Feb 03 '14 at 20:41

1 Answers1

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
Yogi
  • 233
  • 5
  • 19