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
public class NetNamedPipeBinding extends Binding implements IBindingRuntimePreferences
public class NetNamedPipeBinding extends Binding implements IBindingRuntimePreferences
Not applicable.

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) out-of-the-box 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 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 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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft