I have a WCF Channel Factory that has its endpoint modified for a WCF service call. What I want is for the service call to be done on a different context which ordinarily is straight forward. However it is not working for me. I can successfully add the credentials to the endpoint behavior, inspect them, and see them but the call is not made using the ‘NewUser’ credentials.
internal static void UpdateChannelClientBehavior(ChannelFactory factory)
{
factory.Endpoint.Behaviors.Remove<ClientCredentials>();
//MyCustomCredentials is a custom class class variable that inherits System.ServiceModel.Description.ClientCredentials
MyCustomCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
MyCustomCredentials.Windows.ClientCredential = new NetworkCredential("NewUser", "password", "MyDomain");
factory.Endpoint.Behaviors.Add(MyCustomCredentials);
return;
}
So after this code the endpoint indeed has the new Windows Credentials but server side it is still being called under the default context and not with the ‘NewUsers’ credentials. What am I doing incorrectly to make this work?
Thanks!
Actually this code does work:
If you were instantiating an instance of the WCF client proxy directly, another way this could be done is as follows:
I was iterating through many attempts of making code changes and has messed up something downstream that was affecting this code. You can indeed change the context of the call using the code above to impersonate a different user making the WCF call. This comes in very handy if needing to temporarily elevate a call to a WCF service.