Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF throws exception that the server has rejected the client credentials, what is the default security mode for NetTCP in WCF

Tags:

wcf

The WCF is deployed as a windows service in the server. And the client is a windows form applicaiton. When the client is interacting with the WCF server, is there any kind of authentication going on here?

I got how to resolve this here

I want to know what is the default security mode for NetTCP in WCF? I had nothing related with security in my config file as below. So what is the default?

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <behaviors>
        <serviceBehaviors>
            <behavior name="BasicServiceBehavior">
                <serviceMetadata httpGetEnabled="false"/>
                <serviceDebug includeExceptionDetailInFaults="false"/>
                <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="HCCNetTcpBinding" >
                <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="BasicServiceBehavior" name="HCC.SMS4.SERVICES.BASIC.MainServices">
            <endpoint address="" binding="netTcpBinding" contract="HCC.SMS4.SERVICES.BASIC.IMainServices" bindingConfiguration="HCCNetTcpBinding" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            <host>
                <baseAddresses>
                    <add baseAddress="http://xxxx:44008/HCsmsBasicServices/"/>
                    <add baseAddress="net.tcp://xxxx:45008/HCsmsBasicServices/"/>
                </baseAddresses>
            </host>
        </service>
    </services>

    <bindings>
        <netTcpBinding>
            <binding name="HCCNetTcpBinding" maxConnections="1000" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
                      openTimeout="14:00:00" receiveTimeout="14:00:00" sendTimeout="14:00:00">
                <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
            </binding>
        </netTcpBinding>
    </bindings>

</system.serviceModel>
like image 429
Robin Sun Avatar asked Dec 06 '25 22:12

Robin Sun


1 Answers

The transport security mode of the NetTcpBinding is Transport and the ClientCredentialType is Windows. This is equivalent to the following settings.

<netTcpBinding>
  <binding name="netTcp">
    <security mode="Transport">
      <transport clientCredentialType="Windows" />
    </security>
  </binding>
</netTcpBinding>

So when you use the client proxy class to call the service, you could refer to the following code.

ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
            client.ClientCredentials.Windows.ClientCredential.UserName = "administrator";
            client.ClientCredentials.Windows.ClientCredential.Password = "abcd1234!";
var result = client.SayHello();

https://learn.microsoft.com/en-us/dotnet/framework/wcf/system-provided-bindings https://learn.microsoft.com/zh-cn/dotnet/framework/wcf/feature-details/bindings-and-security

Feel free to contact me if you have any questions.

like image 191
Abraham Qian Avatar answered Dec 08 '25 18:12

Abraham Qian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!