MsmqIntegrationBinding 類別

定義

MsmqIntegrationBinding 類別會將 Microsoft Message Queuing (MSMQ) 訊息對應至 Windows Communication Foundation (WCF) 訊息。

public ref class MsmqIntegrationBinding : System::ServiceModel::MsmqBindingBase
public class MsmqIntegrationBinding : System.ServiceModel.MsmqBindingBase
type MsmqIntegrationBinding = class
    inherit MsmqBindingBase
Public Class MsmqIntegrationBinding
Inherits MsmqBindingBase
繼承
MsmqIntegrationBinding

範例

下列組態檔片段說明如何在用戶端上設定 MsmqIntegrationBinding 繫結:

下列組態檔片段說明如何在服務上設定 MsmqIntegrationBinding 繫結:

[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
[ServiceKnownType(typeof(PurchaseOrder))]
public interface IOrderProcessor
{
    [OperationContract(IsOneWay = true, Action = "*")]
    void SubmitPurchaseOrder(MsmqMessage<PurchaseOrder> msg);
}
<ServiceContract(Namespace:="http:'Microsoft.ServiceModel.Samples")> _
<ServiceKnownType(GetType(PurchaseOrder))> _
Public Interface IOrderProcessor
    <OperationContract(IsOneWay:=True, Action:="*")> _
    Sub SubmitPurchaseOrder(ByVal msg As MsmqMessage(Of PurchaseOrder))
End Interface

下列程式碼說明如何以程式設計的方式使用服務上的 MsmqIntegrationBinding 繫結:

public class OrderProcessorService : IOrderProcessor
{
    [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
    public void SubmitPurchaseOrder(MsmqMessage<PurchaseOrder> ordermsg)
    {
        PurchaseOrder po = (PurchaseOrder)ordermsg.Body;
        Random statusIndexer = new Random();
        po.Status = (OrderStates)statusIndexer.Next(3);
        Console.WriteLine("Processing {0} ", po);
    }

    // Host the service within this EXE console application.
public static void Main()
{
    // Get base address from appsettings in configuration.
    Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]);

    // Create a ServiceHost for the CalculatorService type and provide the base address.
    using (ServiceHost serviceHost = new ServiceHost(typeof(IOrderProcessor), 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("The service is running in the following account: {0}", WindowsIdentity.GetCurrent().Name);
        Console.WriteLine("Press <ENTER> to terminate service.");
        Console.WriteLine();
        Console.ReadLine();

    // Close the ServiceHostBase to shutdown the service.
        serviceHost.Close();
    }
}
}
Public Class OrderProcessorService
    Implements IOrderProcessor

    <OperationBehavior(TransactionScopeRequired:=True, TransactionAutoComplete:=True)> _
    Public Sub SubmitPurchaseOrder(ByVal ordermsg As MsmqMessage(Of PurchaseOrder)) Implements IOrderProcessor.SubmitPurchaseOrder
        Dim po As PurchaseOrder = ordermsg.Body
        Dim statusIndexer As New Random()
        po.Status = statusIndexer.Next(3)
        Console.WriteLine("Processing {0} ", po)
    End Sub
End Class

下列程式碼說明如何以程式設計的方式使用用戶端上的 MsmqIntegrationBinding 繫結:

MsmqIntegrationBinding binding = new MsmqIntegrationBinding();
EndpointAddress address = new EndpointAddress("msmq.formatname:DIRECT=OS:.\\private$\\Orders");
ChannelFactory<IOrderProcessor> channelFactory = new ChannelFactory<IOrderProcessor>(binding, address);
IOrderProcessor channel = channelFactory.CreateChannel();

PurchaseOrder po = new PurchaseOrder();
po.customerId = "somecustomer.com";
po.poNumber = Guid.NewGuid().ToString();

PurchaseOrderLineItem lineItem1 = new PurchaseOrderLineItem();
lineItem1.productId = "Blue Widget";
lineItem1.quantity = 54;
lineItem1.unitCost = 29.99F;

PurchaseOrderLineItem lineItem2 = new PurchaseOrderLineItem();
lineItem2.productId = "Red Widget";
lineItem2.quantity = 890;
lineItem2.unitCost = 45.89F;

po.orderLineItems = new PurchaseOrderLineItem[2];
po.orderLineItems[0] = lineItem1;
po.orderLineItems[1] = lineItem2;

MsmqMessage<PurchaseOrder> ordermsg = new MsmqMessage<PurchaseOrder>(po);
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
    channel.SubmitPurchaseOrder(ordermsg);
    scope.Complete();
}
Console.WriteLine("Order has been submitted:{0}", po);
Dim binding As New MsmqIntegrationBinding()
Dim address As New EndpointAddress("msmq.formatname:DIRECT=OS:.\\private$\\Orders")
Dim channelFactory As New ChannelFactory(Of IOrderProcessor)(binding, address)
Dim channel As IOrderProcessor = channelFactory.CreateChannel()

Dim po As New PurchaseOrder()
po.customerId = "somecustomer.com"
po.poNumber = Guid.NewGuid().ToString()

Dim lineItem1 As New PurchaseOrderLineItem()
lineItem1.productId = "Blue Widget"
lineItem1.quantity = 54
lineItem1.unitCost = 29.99F

Dim lineItem2 = New PurchaseOrderLineItem()
lineItem2.productId = "Red Widget"
lineItem2.quantity = 890
lineItem2.unitCost = 45.89F

Dim lineItems(1) As PurchaseOrderLineItem
lineItems(0) = lineItem1
lineItems(1) = lineItem2

po.orderLineItems = lineItems

Dim ordermsg As MsmqMessage(Of PurchaseOrder) = New MsmqMessage(Of PurchaseOrder)(po)
Using scope As New TransactionScope(TransactionScopeOption.Required)
    channel.SubmitPurchaseOrder(ordermsg)
    scope.Complete()
End Using
Console.WriteLine("Order has been submitted:{0}", po)

備註

重要

使用不信任的資料呼叫此類別的方法,會造成安全性上的風險。 呼叫此類別的方法時,請一律使用信任的資料。 如需詳細資訊,請參閱 驗證所有輸入

此系結可用來讓 WCF 應用程式使用 COM、原生 C++ API 或命名空間中 System.Messaging 定義的類型,來回傳送和接收訊息給現有的 MSMQ 應用程式。

建構函式

MsmqIntegrationBinding()

初始化 MsmqIntegrationBinding 類別的新執行個體。

MsmqIntegrationBinding(MsmqIntegrationSecurityMode)

使用指定的 MsmqIntegrationBinding 來初始化 MsmqIntegrationSecurityMode 類別的新執行個體。

MsmqIntegrationBinding(String)

從指定的組態繫結項目設定,初始化 MsmqIntegrationBinding 類別的新執行個體。

屬性

CloseTimeout

取得或設定針對連線所提供的時間間隔 (此連線要在傳輸引發例外狀況之前關閉)。

(繼承來源 Binding)
CustomDeadLetterQueue

取得或設定 URI,其中包含每個應用程式寄不出的信件佇列的位置,所有已過期、無法傳輸或傳遞的訊息都會放到該佇列中。

(繼承來源 MsmqBindingBase)
DeadLetterQueue

取得或設定列舉值,這個值會指出要使用之寄不出的信件佇列類型。

(繼承來源 MsmqBindingBase)
Durable

取得或設定值,這個值會指出由這個繫結處理的訊息是否具有永久性或變動性。

(繼承來源 MsmqBindingBase)
ExactlyOnce

取得或設定值,這個值會指出由這個繫結處理的訊息是否會確實接收一次。

(繼承來源 MsmqBindingBase)
MaxReceivedMessageSize

取得或設定這個繫結所處理之訊息的大小上限 (以位元組為單位)。

(繼承來源 MsmqBindingBase)
MaxRetryCycles

取得或設定嘗試傳遞訊息至接收應用程式的重試循環次數上限。

(繼承來源 MsmqBindingBase)
MessageVersion

取得用戶端所使用的訊息版本及使用繫結所設定的服務。

(繼承來源 Binding)
Name

取得或設定繫結的名稱。

(繼承來源 Binding)
Namespace

取得或設定繫結的 XML 命名空間。

(繼承來源 Binding)
OpenTimeout

取得或設定針對連線所提供的時間間隔 (此連線要在傳輸引發例外狀況之前開啟)。

(繼承來源 Binding)
ReceiveContextEnabled

取得或設定值,這個值表示是否已要求接收內容行為。

(繼承來源 MsmqBindingBase)
ReceiveErrorHandling

取得或設定列舉值,這個值會指定如何處理有害的訊息。

(繼承來源 MsmqBindingBase)
ReceiveRetryCount

取得或設定從應用程式佇列讀取之訊息的立即傳遞嘗試次數上限。

(繼承來源 MsmqBindingBase)
ReceiveTimeout

取得或設定連線中斷之前,可以維持非作用狀態的時間間隔 (在此期間未接收應用程式訊息)。

(繼承來源 Binding)
RetryCycleDelay

取得或設定值,這個值會指出嘗試傳遞無法立即傳遞之訊息時,重試循環之間的時間延遲。

(繼承來源 MsmqBindingBase)
Scheme

傳回這個繫結的配置。

(繼承來源 MsmqBindingBase)
Security

取得與這個繫結關聯的 MsmqIntegrationSecurity

SendTimeout

取得或設定針對寫入作業所提供的時間間隔 (此作業要在傳輸引發例外狀況之前完成)。

(繼承來源 Binding)
SerializationFormat

取得或設定要用於序列化或還原序列化訊息的序列化格式。

TimeToLive

取得或設定時間間隔,這個間隔會指出由此繫結所處理之訊息在到期前可保留在佇列中的時間長度。

(繼承來源 MsmqBindingBase)
UseMsmqTracing

取得或設定值,這個值會指出是否應追蹤由此繫結處理的訊息。

(繼承來源 MsmqBindingBase)
UseSourceJournal

取得或設定值,此值會指出是否要將此繫結處理之訊息的複本儲存在來源日誌佇列。

(繼承來源 MsmqBindingBase)
ValidityDuration

取得或設定值,這個值會指定接收內容功能鎖定訊息的持續期間。

(繼承來源 MsmqBindingBase)

方法

BuildChannelFactory<TChannel>(BindingParameterCollection)

在用戶端上建置通道處理站堆疊,此堆疊會建立指定的通道型別,並滿足繫結參數集合所指定的功能。

(繼承來源 Binding)
BuildChannelFactory<TChannel>(Object[])

在用戶端上建置通道處理站堆疊,此堆疊會建立指定的通道型別,並滿足物件陣列所指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(BindingParameterCollection)

在服務上建置通道接聽程式,此接聽程式會接受指定的通道型別,並滿足繫結參數集合所指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Object[])

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Uri, BindingParameterCollection)

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Uri, Object[])

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Uri, String, BindingParameterCollection)

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Uri, String, ListenUriMode, BindingParameterCollection)

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Uri, String, ListenUriMode, Object[])

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Uri, String, Object[])

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
CanBuildChannelFactory<TChannel>(BindingParameterCollection)

傳回值,這個值指出目前的繫結是否可以在用戶端上建置滿足指定之繫結參數集合的通道處理站堆疊。

(繼承來源 Binding)
CanBuildChannelFactory<TChannel>(Object[])

傳回值,這個值指出目前的繫結程序是否可以在用戶端上建置滿足物件陣列指定之需求的通道處理站堆疊。

(繼承來源 Binding)
CanBuildChannelListener<TChannel>(BindingParameterCollection)

傳回值,這個值指出目前的繫結是否可以在服務上建置滿足指定之繫結參數集合的通道接聽程式堆疊。

(繼承來源 Binding)
CanBuildChannelListener<TChannel>(Object[])

傳回值,這個值指出目前的繫結是否可以在服務上建置滿足物件陣列中指定之準則的通道接聽程式堆疊。

(繼承來源 Binding)
CreateBindingElements()

傳回基本設定檔堆疊中的繫結項目。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetProperty<T>(BindingParameterCollection)

從繫結堆疊的適當層次中,傳回要求的型別物件 (如果有)。

(繼承來源 Binding)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ShouldSerializeName()

傳回繫結的名稱是否應該序列化。

(繼承來源 Binding)
ShouldSerializeNamespace()

傳回繫結的命名空間是否應該序列化。

(繼承來源 Binding)
ShouldSerializeSecurity()

取得一個值,這個值會指定是否應該序列化安全性資訊。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

IBindingRuntimePreferences.ReceiveSynchronously

取得值,這個值指出以同步還是非同步方式處理傳入要求可以比較有效率。

(繼承來源 MsmqBindingBase)

適用於