I have an ASP.NET MVC WebApplication, hosted in server-frontend
, which is client of a WCF application hosted in server-wcf
, both in the same network/domain. Both servers are Windows Server 2012 running IIS 8.
I enabled Windows Authentication and disabled Anonymous in both projects (csproj).
If I call this.User.Identity.Name
inside a Controller in my WebApp, it gives correctly the user logged in (e.g mydomain\alisson).
Both projects have been configured with Windows Authentication in IIS, and WebApp particularly has ASP.NET impersonation enabled. Both have Forms, Basic and Anonymous disabled. Both pools use NetworkService
.
My WCF project is responsible for connecting to SQL Server, and it works properly, since I gave permission to the machine itself in my database (e.g server-wcf$
), and this is exactly what I expect.
Now I'm trying to call a WCF method from my WebApp like so:
var binding = new BasicHttpBinding();
binding.MaxReceivedMessageSize = 10485760;
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
var endPoint = new EndpointAddress(address);
var channelFactory = new ChannelFactory<IMyService>(binding, endPoint);
var client = channelFactory.CreateChannel();
client.GetUser();
and this GetUser()
in my WCF Service is declared as follow:
public GetUser()
{
return ServiceSecurityContext.Current.WindowsIdentity.Name;
}
Which returns domain\server-frontend
instead of domain\alisson
.
I want to make it get the user in WCF, but keep the way WCF connects to database as itself (server-wcf).
My WebApp web.config has the following:
<identity impersonate="true" />
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
Whereas the WCF has the following inside web.config serviceModel:
<bindings>
<basicHttpBinding>
<binding name="AutomatizacaoBinding" maxReceivedMessageSize="10485760">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
Is it possible to achieve this?