The MsmqIntegrationBinding class maps Microsoft Message Queuing (MSMQ) messages to Windows Communication Foundation (WCF) messages.
Public Class MsmqIntegrationBinding _ Inherits MsmqBindingBase
Dim instance As MsmqIntegrationBinding
public class MsmqIntegrationBinding : MsmqBindingBase
public ref class MsmqIntegrationBinding : public MsmqBindingBase
public class MsmqIntegrationBinding extends MsmqBindingBase
This binding can be used to enable WCF applications to send and receive messages to and from existing MSMQ applications that use COM, native C++ APIs or the types defined in the System.Messaging namespace.
The following configuration file snippet illustrates how to configure the MsmqIntegrationBinding binding on the client:
The following configuration file snippet illustrates how to configure the MsmqIntegrationBinding binding on the service:
<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
[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")] [ServiceKnownType(typeof(PurchaseOrder))] public interface IOrderProcessor { [OperationContract(IsOneWay = true, Action = "*")] void SubmitPurchaseOrder(MsmqMessage<PurchaseOrder> msg); }
The following code illustrates how to use the MsmqIntegrationBinding binding on the service programmatically:
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
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(); } } }
The following code illustrates how to use the MsmqIntegrationBinding binding on the client programmatically:
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(2) 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)
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);
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003