Adding Certificate to the net tcp binding results in error stating there are no certificates in ClientCredentials

29 Views Asked by At

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
1

There are 1 best solutions below

0
Jiayao On

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:

NetTcpBinding b = new NetTcpBinding(SecurityMode.TransportWithMessageCredential);
b.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;

Or you can modify the code in web.config as well :

<bindings>  
<netTcpBinding>  
  <binding name="myTcpBinding">  
    <security mode="TransportWithMessageCredential" >  
       <message clientCredentialType="Windows" />  
    </security>  
  </binding>  
</netTcpBinding>  
</bindings> 

Other Settings or more detailed info could be found in this article. Hope it helps.