MsmqIntegrationBinding 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
MsmqIntegrationBinding 类,将 Microsoft 消息队列 (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 绑定:
[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,该 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) |
方法
显式接口实现
IBindingRuntimePreferences.ReceiveSynchronously |
获取一个值,该值指示传入请求是由同步处理更加有效还是异步处理更加有效。 (继承自 MsmqBindingBase) |