Skip to Content
Programming WCF Services, 3rd Edition
book

Programming WCF Services, 3rd Edition

by Juval Lowy
August 2010
Intermediate to advanced
908 pages
26h 22m
English
O'Reilly Media, Inc.
Content preview from Programming WCF Services, 3rd Edition

Message Headers

Every WCF message contains a collection of outgoing and incoming message headers. When the client wishes to send out-of-band parameters to the service, it does so by adding those parameters to the outgoing headers. The service then reads those parameters from the incoming headers.

The operation context offers collections of incoming and outgoing headers, available via the IncomingMessageHeaders and OutgoingMessageHeaders properties:

public sealed class OperationContext : ...
{
   public MessageHeaders IncomingMessageHeaders
   {get;}

   public MessageHeaders OutgoingMessageHeaders
   {get;}

   //More members
}

Each collection is of the type MessageHeaders (that is, a collection of MessageHeader objects):

public sealed class MessageHeaders : ...
{
   public void Add(MessageHeader header);
   public T GetHeader<T>(int index);
   public T GetHeader<T>(string name,string ns);
   //More members
}

The class MessageHeader is not intended for application developers to interact with directly. Instead, use the MessageHeader<T> class, which provides for type-safe and easy conversion from a CLR type parameter to a message header:

public abstract class MessageHeader : ...
{...}

public class MessageHeader<T>
{
   public MessageHeader();
   public MessageHeader(T content);
   public T Content
   {get;set;}
   public MessageHeader GetUntypedHeader(string name,string ns);
   //More members
}

You can use any serializable or data contract type as the type parameter for MessageHeader<T>. You construct a MessageHeader<T> around a CLR ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming WCF Services, 4th Edition

Programming WCF Services, 4th Edition

Juval Lowy, Michael Montgomery
Programming .NET Security

Programming .NET Security

Adam Freeman, Allen Jones

Publisher Resources

ISBN: 9781449382476Supplemental ContentErrata Page