NetMsmqBinding 类

定义

表示适用于跨计算机通信的排队绑定。Represents a queued binding that is suitable for cross-machine communication.

public ref class NetMsmqBinding : System::ServiceModel::MsmqBindingBase
public class NetMsmqBinding : System.ServiceModel.MsmqBindingBase
type NetMsmqBinding = class
    inherit MsmqBindingBase
Public Class NetMsmqBinding
Inherits MsmqBindingBase
继承
NetMsmqBinding

示例

下面的示例演示如何将服务配置为使用 NetMsmqBinding 绑定。The following example shows how to configure a service to use the NetMsmqBinding binding.

首先演示的是配置文件。First, the configuration file.

接下来演示的是实际服务代码。Next, the actual service code.

// Define a service contract. 
[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]
public interface IQueueCalculator
{
    [OperationContract(IsOneWay=true)]
    void Add(double n1, double n2);
    [OperationContract(IsOneWay = true)]
    void Subtract(double n1, double n2);
    [OperationContract(IsOneWay = true)]
    void Multiply(double n1, double n2);
    [OperationContract(IsOneWay = true)]
    void Divide(double n1, double n2);
}
' Define a service contract. 
<ServiceContract(Namespace:="http://Microsoft.ServiceModel.Samples")> _
Public Interface IQueueCalculator
    <OperationContract(IsOneWay:=True)> _
    Sub Add(ByVal n1 As Double, ByVal n2 As Double)
    <OperationContract(IsOneWay := True)> _
    Sub Subtract(ByVal n1 As Double, ByVal n2 As Double)
    <OperationContract(IsOneWay := True)> _
    Sub Multiply(ByVal n1 As Double, ByVal n2 As Double)
    <OperationContract(IsOneWay := True)> _
    Sub Divide(ByVal n1 As Double, ByVal n2 As Double)
End Interface
// Service class that implements the service contract.
// Added code to write output to the console window
public class CalculatorService : IQueueCalculator
{
    [OperationBehavior]
    public void Add(double n1, double n2)
    {
        double result = n1 + n2;
        Console.WriteLine("Received Add({0},{1}) - result: {2}", n1, n2, result);
    }

    [OperationBehavior]
    public void Subtract(double n1, double n2)
    {
        double result = n1 - n2;
        Console.WriteLine("Received Subtract({0},{1}) - result: {2}", n1, n2, result);
    }

    [OperationBehavior]
    public void Multiply(double n1, double n2)
    {
        double result = n1 * n2;
        Console.WriteLine("Received Multiply({0},{1}) - result: {2}", n1, n2, result);
    }

    [OperationBehavior]
    public void Divide(double n1, double n2)
    {
        double result = n1 / n2;
        Console.WriteLine("Received Divide({0},{1}) - result: {2}", n1, n2, result);
    }
}
' Service class that implements the service contract.
' Added code to write output to the console window
Public Class CalculatorService
    Implements IQueueCalculator
    <OperationBehavior> _
    Public Sub Add(ByVal n1 As Double, ByVal n2 As Double) Implements IQueueCalculator.Add
        Dim result As Double = n1 + n2
        Console.WriteLine("Received Add({0},{1}) - result: {2}", n1, n2, result)
    End Sub

    <OperationBehavior> _
    Public Sub Subtract(ByVal n1 As Double, ByVal n2 As Double) Implements IQueueCalculator.Subtract
        Dim result As Double = n1 - n2
        Console.WriteLine("Received Subtract({0},{1}) - result: {2}", n1, n2, result)
    End Sub

    <OperationBehavior> _
    Public Sub Multiply(ByVal n1 As Double, ByVal n2 As Double) Implements IQueueCalculator.Multiply
        Dim result As Double = n1 * n2
        Console.WriteLine("Received Multiply({0},{1}) - result: {2}", n1, n2, result)
    End Sub

    <OperationBehavior> _
    Public Sub Divide(ByVal n1 As Double, ByVal n2 As Double) Implements IQueueCalculator.Divide
        Dim result As Double = n1 / n2
        Console.WriteLine("Received Divide({0},{1}) - result: {2}", n1, n2, result)
    End Sub
End Class
// This is the hosting application. This code can appear directly in the service class as well.
class HostApp
{
    // Host the service within this EXE console application.
    public static void Main()
    {
        // Get MSMQ queue name from appsettings in configuration.
        string queueName = ConfigurationManager.AppSettings["queueName"];

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

        // Get the base address that is used to listen for WS-MetaDataExchange requests.
        // This is useful to generate a proxy for the client.
        string baseAddress = ConfigurationManager.AppSettings["baseAddress"];

        // Create a ServiceHost for the CalculatorService type.
        using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), new Uri(baseAddress)))
        {
            // 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();
        }
    }
}
' This is the hosting application. This code can appear directly in the service class as well.
Friend Class HostApp
    ' Host the service within this EXE console application.
    Public Shared Sub Main()
        ' Get MSMQ queue name from appsettings in configuration.
        Dim queueName As String = ConfigurationManager.AppSettings("queueName")

        ' Create the transacted MSMQ queue if necessary.
        If (Not MessageQueue.Exists(queueName)) Then
            MessageQueue.Create(queueName, True)
        End If

        ' Get the base address that is used to listen for WS-MetaDataExchange requests.
        ' This is useful to generate a proxy for the client.
        Dim baseAddress As String = ConfigurationManager.AppSettings("baseAddress")

        ' Create a ServiceHost for the CalculatorService type.
        Using serviceHost As New ServiceHost(GetType(CalculatorService), New Uri(baseAddress))
            ' 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()
        End Using
    End Sub
End Class

注解

NetMsmqBinding 绑定通过利用消息队列 (MSMQ) 作为传输来提供队列支持,并且为松耦合应用程序、故障隔离、负载均衡和断开连接的操作提供支持。The NetMsmqBinding binding provides support for queuing by using Message Queuing (MSMQ) as a transport and enables support for loosely-coupled applications, failure isolation, load leveling and disconnected operations. 有关这些功能的讨论,请参阅队列概述For a discussion of these features, see Queues Overview.

这是由 Windows Communication Foundation (WCF)提供的系统提供的绑定之一。This is one of the system-provided bindings provided by Windows Communication Foundation (WCF). 建议的过程是使用配置值定义绑定而不是使用基于代码的方法,除了必须将配置值设为已初始化的服务的某些高级方案之外。The recommended procedure is to define the binding using configuration values and not to use a code-based approach, except in certain advanced scenarios where configuration values must be set as a service is initialized.

构造函数

NetMsmqBinding()

初始化 NetMsmqBinding 类的新实例。Initializes a new instance of the NetMsmqBinding class.

NetMsmqBinding(NetMsmqSecurityMode)

使用指定的安全模式初始化 NetMsmqBinding 类的新实例。Initializes a new instance of the NetMsmqBinding class using the specified security mode.

NetMsmqBinding(String)

从指定配置绑定元素的设置中初始化 NetMsmqBinding 类的新实例。Initializes a new instance of the NetMsmqBinding class from the settings of a specified configuration binding element.

属性

CloseTimeout

获取或设置在传输引发异常之前可用于关闭连接的时间间隔。Gets or sets the interval of time provided for a connection to close before the transport raises an exception.

(继承自 Binding)
CustomDeadLetterQueue

获取或设置一个 URI,该 URI 包含每个应用程序的死信队列(该队列用于放置已过期的消息以及传输或传递失败的消息)的位置。Gets or sets a URI that contains the location of the dead-letter queue for each application, where messages that have expired or that have failed transfer or delivery are placed.

(继承自 MsmqBindingBase)
DeadLetterQueue

获取或设置一个枚举值,该值指示要使用的死信队列的类型。Gets or sets an enumeration value that indicates the type of dead-letter queue to use.

(继承自 MsmqBindingBase)
Durable

获取或设置一个值,该值指定此绑定处理的消息是持久的还是可变的。Gets or sets a value that indicates whether the messages processed by this binding are durable or volatile.

(继承自 MsmqBindingBase)
EnvelopeVersion

获取此绑定处理的消息将要使用的 SOAP 版本。Gets the version of SOAP that is used for messages processed by this binding.

ExactlyOnce

获取或设置一个值,该值指示是否只接收一次由此绑定处理的消息。Gets or sets a value that indicates whether messages processed by this binding are received exactly once.

(继承自 MsmqBindingBase)
MaxBufferPoolSize

获取或设置为从通道接收消息的消息缓冲区管理器分配并供其使用的最大内存量。Gets or sets the maximum amount of memory that is allocated for use by the message buffer manager that receives messages from the channel.

MaxReceivedMessageSize

获取或设置此绑定可处理消息的最大字节大小。Gets or sets the maximum size, in bytes, for a message that is processed by this binding.

(继承自 MsmqBindingBase)
MaxRetryCycles

获取或设置尝试向接收应用程序传递消息的最大重试周期数。Gets or sets the maximum number of retry cycles to attempt delivery of messages to the receiving application.

(继承自 MsmqBindingBase)
MessageVersion

获取由绑定所配置的客户端和服务使用的消息版本。Gets the message version used by clients and services configured with the binding.

(继承自 Binding)
Name

获取或设置绑定的名称。Gets or sets the name of the binding.

(继承自 Binding)
Namespace

获取或设置绑定的 XML 命名空间。Gets or sets the XML namespace of the binding.

(继承自 Binding)
OpenTimeout

获取或设置在传输引发异常之前可用于打开连接的时间间隔。Gets or sets the interval of time provided for a connection to open before the transport raises an exception.

(继承自 Binding)
QueueTransferProtocol

获取或设置一个枚举值,该值指示此绑定使用的排队信道传输。Gets or sets an enumeration value that indicates the queued communication channel transport that this binding uses.

ReaderQuotas

获取或设置与此绑定关联的 XmlDictionaryReaderQuotasGets or sets the XmlDictionaryReaderQuotas that is associated with this binding.

ReceiveContextEnabled

获取或设置一个指示是否请求接收上下文行为的值。Gets or sets a value that indicates whether the receive context behavior is requested.

(继承自 MsmqBindingBase)
ReceiveErrorHandling

获取或设置一个枚举值,该值指定如何处理病毒消息。Gets or sets an enumeration value that specifies how poison messages are handled.

(继承自 MsmqBindingBase)
ReceiveRetryCount

获取或设置从应用程序队列读取的消息的最大立即传递尝试次数。Gets or sets the maximum number of immediate delivery attempts on a message that is read from the application queue.

(继承自 MsmqBindingBase)
ReceiveTimeout

获取或设置连接在撤消之前保持非活动状态的最大时间间隔,在此时间间隔内未接收任何应用程序消息。Gets or sets the interval of time that a connection can remain inactive, during which no application messages are received, before it is dropped.

(继承自 Binding)
RetryCycleDelay

获取或设置一个值,该值指示尝试传递无法立即传递的消息时,各个重试周期之间的时间延迟。Gets or sets a value that indicates the time delay between retry cycles when attempting to deliver a message that cannot be delivered immediately.

(继承自 MsmqBindingBase)
Scheme

返回此绑定的方案。Returns the scheme for this binding.

(继承自 MsmqBindingBase)
Security

获取或设置与此绑定关联的 NetMsmqSecurityGets or sets the NetMsmqSecurity that is associated with this binding.

SendTimeout

获取或设置在传输引发异常之前可用于完成写入操作的时间间隔。Gets or sets the interval of time provided for a write operation to complete before the transport raises an exception.

(继承自 Binding)
TimeToLive

获取或设置一个时间间隔,该时间间隔指示此绑定处理的消息在过期之前可以保留在队列中的时间长度。Gets or sets the interval of time that indicates how long the messages processed by this binding can be in the queue before they expire.

(继承自 MsmqBindingBase)
UseActiveDirectory

获取或设置一个值,该值指示是否应该使用 Active Directory 来转换队列地址。Gets or sets a value that indicates whether queue addresses should be converted using Active Directory.

UseMsmqTracing

获取或设置一个值,该值指示是否应跟踪由此绑定处理的消息。Gets or sets a value that indicates whether messages processed by this binding should be traced.

(继承自 MsmqBindingBase)
UseSourceJournal

获取或设置一个值,该值指示是否应将此绑定处理的消息副本存储到源日记队列中。Gets or sets a value that indicates whether copies of messages processed by this binding should be stored in the source journal queue.

(继承自 MsmqBindingBase)
ValidityDuration

获取或设置一个值,该值指定由接收上下文功能锁定消息的持续时间。Gets or sets a value that specifies the duration a message will be locked by the receive context feature.

(继承自 MsmqBindingBase)

方法

BuildChannelFactory<TChannel>(BindingParameterCollection)

在客户端上生成通道工厂堆栈,此通道工厂堆栈创建具有指定类型的通道并满足绑定参数集合所指定的功能。Builds the channel factory stack on the client that creates a specified type of channel and that satisfies the features specified by a collection of binding parameters.

(继承自 Binding)
BuildChannelFactory<TChannel>(Object[])

在客户端上生成通道工厂堆栈,该通道工厂堆栈创建具有指定类型的通道并满足对象数组所指定的功能。Builds the channel factory stack on the client that creates a specified type of channel and that satisfies the features specified by an object array.

(继承自 Binding)
BuildChannelListener<TChannel>(BindingParameterCollection)

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足绑定参数集合所指定的功能。Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified by a collection of binding parameters.

(继承自 Binding)
BuildChannelListener<TChannel>(Object[])

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.

(继承自 Binding)
BuildChannelListener<TChannel>(Uri, BindingParameterCollection)

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.

(继承自 Binding)
BuildChannelListener<TChannel>(Uri, Object[])

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.

(继承自 Binding)
BuildChannelListener<TChannel>(Uri, String, BindingParameterCollection)

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.

(继承自 Binding)
BuildChannelListener<TChannel>(Uri, String, ListenUriMode, BindingParameterCollection)

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.

(继承自 Binding)
BuildChannelListener<TChannel>(Uri, String, ListenUriMode, Object[])

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.

(继承自 Binding)
BuildChannelListener<TChannel>(Uri, String, Object[])

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.

(继承自 Binding)
CanBuildChannelFactory<TChannel>(BindingParameterCollection)

返回一个值,该值指示当前绑定是否可以在客户端上生成满足指定绑定参数集合的通道工厂堆栈。Returns a value that indicates whether the current binding can build a channel factory stack on the client that satisfies the collection of binding parameters specified.

(继承自 Binding)
CanBuildChannelFactory<TChannel>(Object[])

返回一个值,该值指示当前绑定是否可以在客户端上生成满足对象数组所指定的需求的通道工厂堆栈。Returns a value that indicates whether the current binding can build a channel factory stack on the client that satisfies the requirements specified by an object array.

(继承自 Binding)
CanBuildChannelListener<TChannel>(BindingParameterCollection)

返回一个值,该值指示当前绑定是否可以在服务上生成满足指定绑定参数集合的通道侦听器堆栈。Returns a value that indicates whether the current binding can build a channel listener stack on the service that satisfies the collection of binding parameters specified.

(继承自 Binding)
CanBuildChannelListener<TChannel>(Object[])

返回一个值,该值指示当前绑定是否可以在服务上生成满足对象数组所指定的条件的通道侦听器堆栈。Returns a value that indicates whether the current binding can build a channel listener stack on the service that satisfies the criteria specified in an array of objects.

(继承自 Binding)
CreateBindingElements()

返回一个包含在当前绑定中的已排序的绑定元素集合。Returns an ordered collection of binding elements contained in the current binding.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetProperty<T>(BindingParameterCollection)

从绑定堆栈的适当层返回所请求的类型化对象(如果存在)。Returns a typed object requested, if present, from the appropriate layer in the binding stack.

(继承自 Binding)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ShouldSerializeName()

返回是否应序列化绑定名称。Returns whether the name of the binding should be serialized.

(继承自 Binding)
ShouldSerializeNamespace()

返回是否应序列化绑定命名空间。Returns whether the namespace of the binding should be serialized.

(继承自 Binding)
ShouldSerializeReaderQuotas()

返回一个值,该值指示 ReaderQuotas 属性是否已更改,不再是默认值且应对其进行序列化。Returns a value that indicates whether the ReaderQuotas property has changed from its default value and should be serialized.

ShouldSerializeSecurity()

返回一个值,该值指示 Security 属性是否已更改,不再是默认值且应对其进行序列化。Returns a value that indicates whether the Security property has changed from its default value and should be serialized.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

IBindingRuntimePreferences.ReceiveSynchronously

获取一个值,该值指示传入请求是由同步处理更加有效还是异步处理更加有效。Gets a value that indicates whether incoming requests can be handled more efficiently synchronously or asynchronously.

(继承自 MsmqBindingBase)

适用于