SRMP

Download sample

This sample demonstrates how to perform transacted queued communication by using Message Queuing (MSMQ) over HTTP.

Note

The WCF samples may already be installed on your machine. Check this (default) directory before continuing: <InstallDrive>:\Samples\WCFWFCardspaceIf this directory doesn’t exist, click the download sample link at the top of this page. Note that this will download and install all of the WF, WCF, and CardSpace samples, you will only have to do this once. The sample is located in the following directory <InstallDrive>:\Samples\WCFWFCardSpace\WCF\Basic\Binding\Net\Msmq\Srmp.

In queued communication, the client communicates to the service using a queue. More precisely, the client sends messages to a queue. The service receives messages from the queue. The service and client therefore, do not have to be running at the same time to communicate using a queue.

MSMQ enables the use of HTTP (including the use of HTTPS) to send messages to a queue. In this example, we demonstrate using Windows Communication Foundation (WCF) queued communication and how to send messages over HTTP. MSMQ uses a protocol called SRMP, which is a SOAP-based protocol for communication over HTTP.

To set up, build, and run the sample

  1. Ensure that you have performed the One-Time Set Up Procedure for the Windows Communication Foundation Samples.

  2. To build the C# or Visual Basic .NET edition of the solution, follow the instructions in Building the Windows Communication Foundation Samples.

  3. To run the sample in a single- or cross-machine configuration, follow the instructions in Running the Windows Communication Foundation Samples.

  4. Before running the sample in Add/Remove Windows Components, ensure that MSMQ is installed with HTTP support. Installing HTTP support automatically installs Internet Information Services (IIS) and adds the protocol support in IIS for MSMQ.

  5. If you want to be certain that HTTP is used for communication, you can enable MSMQ to run in hardened mode. This ensures that no messages to any queue hosted on the machine can arrive using any non-HTTP transport.

  6. After you have selected MSMQ to run in hardened mode, the machine requires a re-boot on Windows Server 2003.

  7. Run the service.

  8. Run the client. Ensure that you change the endpoint address to point to the machine name or IP address instead of localhost. The client sends a message and exits.

Requirements

To run this sample, IIS must be installed on both the service and the client machines in addition to MSMQ.

Demonstrates

The sample demonstrates sending WCF queued messages using MSMQ over HTTP. This is also called SRMP messaging. When a queued message is sent, MSMQ on the sending machine transfers the messages to the receiving queue manager over TCP or HTTP transport. By choosing SRMP, the user indicates the choice of HTTP as a transport for queue transfer. SRMP Secure enables the use of HTTPS.

Example

The sample code is based on the transacted sample. How you send a message to the queue and receive a message from the queue using SRMP is the same as sending and receiving messages using a Native protocol.

The configuration for the client is changed to indicate the choice of the queue transfer protocol. The queue transfer protocol can be one of Native, SRMP or SrmpSecure. By default, the transfer protocol is Native. The client and service specify in the configuration to use SRMP in this example.

There are limitations to SRMP in relation to transport security. The default MSMQ transport security requires Active Directory that requires that the sending queue manager and the receiving queue manager reside in the same Windows domain. This is not possible when sending messages over HTTP boundary. As such, the default transport security does not work. The transport security must be set to Certificate if transport security is desired. Message security can also be used to secure the message. In this sample, both transport and message security is turned off to illustrate SRMP messaging.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.serviceModel>

    <client>
      <!-- Define NetMsmqEndpoint -->
      <endpoint name="OrderProcessorEndpoint"
           address=
          "net.msmq://localhost/private/ServiceModelSamplesSrmp" 
           bindingConfiguration="srmpBinding" 
           binding="netMsmqBinding" 
           contract="IOrderProcessor" />
    </client>
    <bindings>
      <netMsmqBinding>
        <binding name="srmpBinding"
                 queueTransferProtocol="Srmp">
          <security mode="None"></security>
        </binding>
      </netMsmqBinding>
    </bindings>
  </system.serviceModel>

</configuration>

Running the sample yields the following output.

Processing Purchase Order: 556b70be-31ee-4a3b-8df4-ed5e538015a4 
Customer: somecustomer.com 
OrderDetails 
    Order LineItem: 54 of Blue Widget @unit price: $29.99 
    Order LineItem: 890 of Red Widget @unit price: $45.89 
    Total cost of this order: $42461.56 
    Order status: Pending

© 2007 Microsoft Corporation. All rights reserved.