NetMsmqBinding 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示適合跨電腦通訊的佇列繫結。
public ref class NetMsmqBinding : System::ServiceModel::MsmqBindingBase
public class NetMsmqBinding : System.ServiceModel.MsmqBindingBase
type NetMsmqBinding = class
inherit MsmqBindingBase
Public Class NetMsmqBinding
Inherits MsmqBindingBase
- 繼承
範例
下列範例說明如何設定服務以使用 NetMsmqBinding 繫結。
首先是組態檔。
接著是實際的服務程式碼。
// 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) 做為傳輸,提供佇列的支援,並可支援結合鬆散的應用程式、失敗隔離、負載平均和中斷連接作業。 如需這些功能的討論,請參閱 佇列概觀。
這是 Windows Communication Foundation (WCF) 所提供的其中一個系統提供的系結。 建議的程序為使用組態值來定義繫結,且不使用程式碼的方法,除了在初始化服務時必須設定組態值的特定進階情況中。
建構函式
NetMsmqBinding() |
初始化 NetMsmqBinding 類別的新執行個體。 |
NetMsmqBinding(NetMsmqSecurityMode) |
使用指定的安全性模式,初始化 NetMsmqBinding 類別的新執行個體。 |
NetMsmqBinding(String) |
從指定的組態繫結項目設定,初始化 NetMsmqBinding 類別的新執行個體。 |
屬性
CloseTimeout |
取得或設定針對連線所提供的時間間隔 (此連線要在傳輸引發例外狀況之前關閉)。 (繼承來源 Binding) |
CustomDeadLetterQueue |
取得或設定 URI,其中包含每個應用程式寄不出的信件佇列的位置,所有已過期、無法傳輸或傳遞的訊息都會放到該佇列中。 (繼承來源 MsmqBindingBase) |
DeadLetterQueue |
取得或設定列舉值,這個值會指出要使用之寄不出的信件佇列類型。 (繼承來源 MsmqBindingBase) |
Durable |
取得或設定值,這個值會指出由這個繫結處理的訊息是否具有永久性或變動性。 (繼承來源 MsmqBindingBase) |
EnvelopeVersion |
取得 SOAP 的版本,用於由此繫結處理的訊息。 |
ExactlyOnce |
取得或設定值,這個值會指出由這個繫結處理的訊息是否會確實接收一次。 (繼承來源 MsmqBindingBase) |
MaxBufferPoolSize |
取得或設定配置供從通道接收訊息之訊息緩衝區管理員使用的最大記憶體量。 |
MaxReceivedMessageSize |
取得或設定這個繫結所處理之訊息的大小上限 (以位元組為單位)。 (繼承來源 MsmqBindingBase) |
MaxRetryCycles |
取得或設定嘗試傳遞訊息至接收應用程式的重試循環次數上限。 (繼承來源 MsmqBindingBase) |
MessageVersion |
取得用戶端所使用的訊息版本及使用繫結所設定的服務。 (繼承來源 Binding) |
Name |
取得或設定繫結的名稱。 (繼承來源 Binding) |
Namespace |
取得或設定繫結的 XML 命名空間。 (繼承來源 Binding) |
OpenTimeout |
取得或設定針對連線所提供的時間間隔 (此連線要在傳輸引發例外狀況之前開啟)。 (繼承來源 Binding) |
QueueTransferProtocol |
取得或設定列舉值,這個值表示此繫結所使用的佇列通訊通道傳輸。 |
ReaderQuotas |
取得或設定與這個繫結關聯的 XmlDictionaryReaderQuotas。 |
ReceiveContextEnabled |
取得或設定值,這個值表示是否已要求接收內容行為。 (繼承來源 MsmqBindingBase) |
ReceiveErrorHandling |
取得或設定列舉值,這個值會指定如何處理有害的訊息。 (繼承來源 MsmqBindingBase) |
ReceiveRetryCount |
取得或設定從應用程式佇列讀取之訊息的立即傳遞嘗試次數上限。 (繼承來源 MsmqBindingBase) |
ReceiveTimeout |
取得或設定連線中斷之前,可以維持非作用狀態的時間間隔 (在此期間未接收應用程式訊息)。 (繼承來源 Binding) |
RetryCycleDelay |
取得或設定值,這個值會指出嘗試傳遞無法立即傳遞之訊息時,重試循環之間的時間延遲。 (繼承來源 MsmqBindingBase) |
Scheme |
傳回這個繫結的配置。 (繼承來源 MsmqBindingBase) |
Security |
取得或設定與這個繫結關聯的 NetMsmqSecurity。 |
SendTimeout |
取得或設定針對寫入作業所提供的時間間隔 (此作業要在傳輸引發例外狀況之前完成)。 (繼承來源 Binding) |
TimeToLive |
取得或設定時間間隔,這個間隔會指出由此繫結所處理之訊息在到期前可保留在佇列中的時間長度。 (繼承來源 MsmqBindingBase) |
UseActiveDirectory |
傳回或設定值,這個值表示是否應該使用 Active Directory 來轉換佇列位址。 |
UseMsmqTracing |
取得或設定值,這個值會指出是否應追蹤由此繫結處理的訊息。 (繼承來源 MsmqBindingBase) |
UseSourceJournal |
取得或設定值,此值會指出是否要將此繫結處理之訊息的複本儲存在來源日誌佇列。 (繼承來源 MsmqBindingBase) |
ValidityDuration |
取得或設定值,這個值會指定接收內容功能鎖定訊息的持續期間。 (繼承來源 MsmqBindingBase) |
方法
明確介面實作
IBindingRuntimePreferences.ReceiveSynchronously |
取得值,這個值指出以同步還是非同步方式處理傳入要求可以比較有效率。 (繼承來源 MsmqBindingBase) |