The Message Type

There are a number of scenarios where you may need to get your hands on raw messages that pass between client and service. The service model provides you with a Message type with direct access to message headers, message body elements, and other properties associated with a SOAP message. Untyped messages like this make it possible to develop generic service operations that do not do the work of serialization and deserialization; instead, they act as a pass-through for messages. Web service intermediaries and content-based routers are examples of service endpoints that can accept any message while still inspecting appropriate message headers or content and forwarding to the rightful recipient.

In this section, I’ll introduce you to several advanced concepts related to the use of untyped messages including:

  • Defining a service contract that works with untyped messages

  • Using the Message type to create and process messages

  • Encapsulating functionality by inheriting Message

  • Working with the MessageHeader type

Lab: Working with Raw Messages

For this lab, you will convert an existing service to work with raw messages. In the process you’ll learn how to create messages from scratch, how to process incoming untyped messages, and how to work with the serialization process between messages and CLR types. The purpose of this lab is to illustrate several aspects of raw message serialization, using the Message type. Later in this section of the chapter, I’ll discuss some more practical ...

Get Learning WCF now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.