NetMsmqBinding 构造函数

定义

初始化 NetMsmqBinding 类的新实例。

重载

NetMsmqBinding()

初始化 NetMsmqBinding 类的新实例。

NetMsmqBinding(NetMsmqSecurityMode)

使用指定的安全模式初始化 NetMsmqBinding 类的新实例。

NetMsmqBinding(String)

从指定配置绑定元素的设置中初始化 NetMsmqBinding 类的新实例。

NetMsmqBinding()

初始化 NetMsmqBinding 类的新实例。

public:
 NetMsmqBinding();
public NetMsmqBinding ();
Public Sub New ()

适用于

NetMsmqBinding(NetMsmqSecurityMode)

使用指定的安全模式初始化 NetMsmqBinding 类的新实例。

public:
 NetMsmqBinding(System::ServiceModel::NetMsmqSecurityMode securityMode);
public NetMsmqBinding (System.ServiceModel.NetMsmqSecurityMode securityMode);
new System.ServiceModel.NetMsmqBinding : System.ServiceModel.NetMsmqSecurityMode -> System.ServiceModel.NetMsmqBinding
Public Sub New (securityMode As NetMsmqSecurityMode)

参数

securityMode
NetMsmqSecurityMode

用于初始化新实例的安全模式。

例外

示例

下面的代码演示如何使用安全模式构造 NetMsmqBinding

NetMsmqBinding binding = new NetMsmqBinding(NetMsmqSecurityMode.Message);

适用于

NetMsmqBinding(String)

从指定配置绑定元素的设置中初始化 NetMsmqBinding 类的新实例。

public:
 NetMsmqBinding(System::String ^ configurationName);
public NetMsmqBinding (string configurationName);
new System.ServiceModel.NetMsmqBinding : string -> System.ServiceModel.NetMsmqBinding
Public Sub New (configurationName As String)

参数

configurationName
String

configurationName 属性的值,该值标识其设置用于初始化绑定的 binding 元素。

示例

下面的代码演示如何实例化 NetMsmqBinding 类的实例。

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();
}

注解

此名称覆盖运行时分配给 NetMsmqBinding 配置文件中的 元素的任何配置名称。

适用于