Click here to Skip to main content
15,306,017 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I have a silverlight application which fetches data from a WCF Service hosted under a Windows Service which runs under the "Local System" account i.e. NT AUTHORITY/ SYSTEM.

I have enabled Windows Authentication on this WCF service using the below in my App.config

    <behavior name="webHttpBehavior"> 
      <webhttp /> 
    <behavior name="defaultServiceBehavior"> 
      <servicemetadata httpgetenabled="true" /> 
      <servicedebug includeexceptiondetailinfaults="true" /> 
    <binding name="winAuthBasicHttpBinding" opentimeout="05:00" sendtimeout="05:00"> 
      <security mode="TransportCredentialOnly"> 
        <transport clientcredentialtype="Windows" /> 
<servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="true" /> 
  <service behaviorconfiguration="defaultServiceBehavior" name="DataService.CrossDomainService"> 
    <endpoint address="" behaviorconfiguration="webHttpBehavior" binding="webHttpBinding" contract="DataService.ICrossDomainService"> 
        <dns value="" /> 
        <add baseaddress="" /> 
  <service behaviorconfiguration="defaultServiceBehavior" name="DataService.NewDataService">         
    <endpoint address="" binding="basicHttpBinding" bindingconfiguration="winAuthBasicHttpBinding" contract="DataService.INewDataService"> 
        <dns value="" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
        <add baseaddress="" /> 


I have also enabled Windows Authentication in the connection string for Oracle using Integrated Security=SSPI as below:

<add name="netTiersConnectionString" connectionstring="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=;Integrated Security=SSPI; Min Pool Size= 1; Max Pool Size= 5;" /> 

Now when the Silverlight app makes a call to the WCF Service, the database connection happens using NT AUTHORITY/SYSTEM account instead of domainname/username credentials of the logged in user in the Silverlight app which itself uses Windows Authentication. Hence I get the invalid username error.

The same configurations work fine when I host the WCF service in a console application. But when I host in a windows service, it runs under a Local System account and hence I guess this issue.

What can I do so that the database connection is made using windows authentication credentials of logged in user and not the Local System account?

Thanks, Pankaj Chamria

1 solution

Now I'm not sure, but I beleave the account used as login to oracle is the one which runs the service not the one which has called the service.
You should look into impersonation[^]

So in you WCF method do something like the below (taken from the site I linked):
WindowsIdentity callerWindowsIdentity =         ServiceSecurityContext.Current.WindowsIdentity;
if (callerWindowsIdentity == null)
    throw new InvalidOperationException("The caller cannot be mapped to a WindowsIdentity");
using (callerWindowsIdentity.Impersonate())
    //Do your thing here

Pankaj Chamria 11-Aug-11 8:10am
Perfect! You pointed me in the right direction. The article link helped me find the answer. As I wanted the impersonation for my entire WCF service functions, I just used the attribute on top of every OperationContract and it worked like a charm..

[OperationBehavior(Impersonation = ImpersonationOption.Required)]

Thanks Simon!
Simon Bang Terkildsen 6-Oct-11 12:24pm
My pleasure
Espen Harlinn 6-Oct-11 10:36am
Simon Bang Terkildsen 6-Oct-11 12:24pm
Thank you, Espen

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900