Export (0) Print
Expand All

NetNamedPipeBinding Class

Provides a secure and reliable binding that is optimized for on-machine communication.

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

public class NetNamedPipeBinding : Binding, 
	IBindingRuntimePreferences

The NetNamedPipeBinding generates a run-time communication stack by default, which uses transport security, named pipes for message delivery, and a binary message encoding. This binding is an appropriate Windows Communication Foundation (WCF) system-provided choice for on-machine communication. It also supports transactions.

The default configuration for the NetNamedPipeBinding is similar to the configuration provided by the NetTcpBinding, but it is simpler because the WCF implementation is only meant for on-machine use and consequently there are fewer exposed features. The most notable difference is that the SecurityMode setting only offers the None and Transport options. SOAP security support is not an included option. The security behavior is configurable using the optional securityMode parameter in NetNamedPipeBinding(NetNamedPipeSecurityMode) the constructor.

The following example shows the part of the configuration file that contains the section for the NetNamedPipeBinding with values set to defaults.

<bindings>
  <!-- 
        Following is the expanded configuration section for a NetNamedPipeBinding.
        Each property is configured with the default value.
     -->
  <netNamedPipeBinding>
    <binding name="Binding1" 
             hostNameComparisonMode="StrongWildcard" 
             maxBufferSize="65536"
             maxConnections="10"
             maxReceivedMessageSize="65536"
             receiveTimeout="00:10:00"
             transactionFlow="false">
      <security mode="Transport">
      </security>
    </binding>
  </netNamedPipeBinding>
</bindings>

The following example shows how to programmatically use the NetNamedPipeBinding class.

    [ServiceContract(Namespace = "http://UE.Samples")]
    public interface ICalculator
    {
        [OperationContract]
        double Add(double n1, double n2);
    }

    // Service class which implements the service contract. 
    public class CalculatorService : ICalculator
    {
        public double Add(double n1, double n2)
        {
            return n1 + n2;
        }

        public static void Main()
        {
            Uri baseAddress = new Uri("http://localhost:8000/uesamples/service");
            string address = "net.pipe://localhost/uesamples/calc";

            // Create a ServiceHost for the CalculatorService type and provide the base address. 
            using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
            {
                NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
                serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, address);

                // Add a mex endpoint
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.HttpGetUrl = new Uri("http://localhost:8001/uesamples");
                serviceHost.Description.Behaviors.Add(smb);

		long maxBufferPoolSize = binding.MaxBufferPoolSize;

		int maxBufferSize = binding.MaxBufferSize;

		int maxConnections = binding.MaxConnections;

		long maxReceivedMessageSize =
		    binding.MaxReceivedMessageSize;

		NetNamedPipeSecurity security = binding.Security;

		string scheme = binding.Scheme;

		XmlDictionaryReaderQuotas readerQuotas =
			binding.ReaderQuotas;

		BindingElementCollection bCollection = binding.CreateBindingElements();

		HostNameComparisonMode hostNameComparisonMode =
			binding.HostNameComparisonMode;

		bool TransactionFlow = binding.TransactionFlow;

		TransactionProtocol transactionProtocol =
			binding.TransactionProtocol;

		EnvelopeVersion envelopeVersion =
			binding.EnvelopeVersion;

		TransferMode transferMode =
			binding.TransferMode;


				
                serviceHost.Open();

                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();

                serviceHost.Close();
            }
        }

	static void SnippetReceiveSynchronously ()
	{

		NetNamedPipeBinding binding = new NetNamedPipeBinding();
		IBindingRuntimePreferences s  =
		       binding.GetProperty<IBindingRuntimePreferences>
		       (new BindingParameterCollection());
		bool receiveSynchronously = s.ReceiveSynchronously;


	}
    }

System.Object
  System.ServiceModel.Channels.Binding
    System.ServiceModel.NetNamedPipeBinding

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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Community Additions

ADD
Show:
© 2014 Microsoft