NetMsmqBinding Constructors

Definition

Initializes a new instance of the NetMsmqBinding class.

Overloads

NetMsmqBinding()

Initializes a new instance of the NetMsmqBinding class.

NetMsmqBinding(NetMsmqSecurityMode)

Initializes a new instance of the NetMsmqBinding class using the specified security mode.

NetMsmqBinding(String)

Initializes a new instance of the NetMsmqBinding class from the settings of a specified configuration binding element.

NetMsmqBinding()

Initializes a new instance of the NetMsmqBinding class.

C#
public NetMsmqBinding();

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

NetMsmqBinding(NetMsmqSecurityMode)

Initializes a new instance of the NetMsmqBinding class using the specified security mode.

C#
public NetMsmqBinding(System.ServiceModel.NetMsmqSecurityMode securityMode);

Parameters

securityMode
NetMsmqSecurityMode

The security mode with which to initialize the new instance.

Exceptions

The value is not one of the NetMsmqSecurityMode values.

Examples

The following code shows how to construct the NetMsmqBinding with a security mode.

C#
NetMsmqBinding binding = new NetMsmqBinding(NetMsmqSecurityMode.Message);

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

NetMsmqBinding(String)

Initializes a new instance of the NetMsmqBinding class from the settings of a specified configuration binding element.

C#
public NetMsmqBinding(string configurationName);

Parameters

configurationName
String

The value of the configurationName attribute that identifies the binding element whose settings are used to initialize the binding.

Examples

The following code shows how to instantiate an instance of NetMsmqBinding class.

C#
string queueName = ".\\private$\\ServiceModelSamples";

// Create the transacted MSMQ queue if necessary.
if (!MessageQueue.Exists(queueName))
    MessageQueue.Create(queueName, true);

string baseAddress = "http://localhost:8000/queuedCalculator";
string endpointAddress = "net.msmq://localhost/private/ServiceModelSamples";

// Create a ServiceHost for the CalculatorService type.
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), new Uri(baseAddress)))
{
    NetMsmqBinding binding = new NetMsmqBinding();
    serviceHost.AddServiceEndpoint(typeof(IQueueCalculator), binding, endpointAddress);

    // Add a MEX endpoint.
    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    serviceHost.Description.Behaviors.Add(smb);

    // Open the ServiceHostBase to create listeners and start listening for messages.
    serviceHost.Open();

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

    // Close the ServiceHostBase to shutdown the service.
    serviceHost.Close();
}

Remarks

This name overwrites any configuration name at runtime that was assigned to the NetMsmqBinding element in a configuration file.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1