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

StackOverflow https://stackoverflow.com/questions/21492023

  •  05-10-2022
  •  | 
  •  

سؤال

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.

هل كانت مفيدة؟

المحلول

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top