NetTcpSecurity Class
Collapse the table of content
Expand the table of content

NetTcpSecurity Class


Specifies the types of transport-level and message-level security used by an endpoint configured with a NetTcpBinding.

Namespace:   System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)


public sealed class NetTcpSecurity


Initializes a new instance of the NetTcpSecurity class.


Gets the type of message-level security requirements for a service configured with a NetTcpBinding.


Gets or sets whether message-level security and transport-level security are used by an endpoint configured with a NetTcpBinding.


Gets the type of message-level security requirements for an endpoint configured with a NetTcpBinding.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Returns a string that represents the current object.(Inherited from Object.)

Each of the standard bindings provides parameters for controlling the transfer security requirements. These parameters typically include the security mode that specified whether message-level or transport-level security is used and the choice of client credential type. Based on the choice of options these parameters present, a channel stack is constructed with appropriate security.

The system-provided bindings supplied by Windows Communication Foundation (WCF) are a set designed to meet some of the most common scenario requirements. Each of these bindings allows the specification of security requirements for some specific targeted scenarios.

NetTcpSecurity provides the security specifications for NetTcpBinding. This is a secure, reliable, optimized binding suitable for cross-machine communication. By default it generates a run-time communication stack that supports TCP for message delivery and Windows Security for message security and authentication, WS-ReliableMessaging for reliability, and binary message encoding.

This class is instantiated by the NetTcpBinding, and can be accessed by a read-only property called Security. Because this property is read-only you cannot make changes to the returned object. If you want to control the creation of the NetTcpSecurity object, you can derive a class from NetTcpBinding.

The following code shows how to retrieve the NetTcpSecurity object from a NetTcpBinding and prints out the various settings it contains:

using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
    ServiceEndpointCollection endpoints = serviceHost.Description.Endpoints;
    ServiceEndpoint endpoint = endpoints.Find(typeof(ICalculator));

    NetTcpBinding binding = (NetTcpBinding) endpoint.Binding;

    NetTcpSecurity security = binding.Security;
    MessageSecurityOverTcp msTcp = security.Message;

    Console.WriteLine("Dumping NetTcpSecurity object:");
    Console.WriteLine("\t\tAlgorithm Suite: {0}", msTcp.AlgorithmSuite);
    Console.WriteLine("\t\tClient Credential Type: {0}", msTcp.ClientCredentialType);

    Console.WriteLine("\tSecurity Mode: {0}", security.Mode);

    TcpTransportSecurity tsTcp = security.Transport;
    Console.WriteLine("\t\tClient Credential Type: {0}", tsTcp.ClientCredentialType);
    Console.WriteLine("\t\tProtectionLevel: {0}", tsTcp.ProtectionLevel);

    // The service can now be accessed.
    Console.WriteLine("The service is ready.");
    Console.WriteLine("Press <ENTER> to terminate service.");

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 3.0
Portable Class Library
Supported in: portable .NET platforms

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
© 2015 Microsoft