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,其中包含每個應用程式寄不出的信件佇列的位置,所有已過期、無法傳輸或傳遞的訊息都會放到該佇列中。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)

適用於