My Code looks like this. I have removed some code blocks for brevity. This code works for wsHttp Binding but not netTcp. Am I missing something?
Binding binding = _wcfBindingProvider.GetWcfBinding(bindingName);//read from config
//read cert from store and add. this is successful
ClientCredentials clientCredentials =_clientCredentialsProvider.CreateClientCredentials();
BindingParameterCollection bindingParameters = new BindingParameterCollection();
bindingParameters.Add(clientCredentials);
foreach (var behavior in behaviors)
{
bindingParameters.Add(behavior);
}
IChannelFactory<IRequestChannel> factory = null;
factory = binding.BuildChannelFactory<IRequestChannel>(bindingParameters);
factory.Open(); //ERROR. No certificate present in Client Credentials
When using nettcpbinding, the transport level security provided by default is windows (you need certificate). So you need to set the Mode and ClientCredentialType to TransportWithMessageCredential and Certificate like below in your code:
Or you can modify the code in web.config as well :
Other Settings or more detailed info could be found in this article. Hope it helps.