Class MessageHelper
Provides extension helper methods for working with WCF messages.
Inherited Members
Namespace: Nevatech.Vsb.Repository
Assembly: Nevatech.Vsb.Repository.dll
Syntax
public static class MessageHelper
Methods
ChangeMessageVersion(Message, MessageVersion)
Performs basic message version conversion by copying message body and custom headers from the original message to the new message.
Declaration
[SuppressMessage("Microsoft.Reliability", "CA2000: Dispose objects before losing scope")]
public static Message ChangeMessageVersion(this Message message, MessageVersion targetVersion)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Original message that needs to converted. |
| MessageVersion | targetVersion | Message version of the converted message. |
Returns
| Type | Description |
|---|---|
| Message | New message with the same content as the original one, but with requested message envelope and addressing version. |
Clone(HttpRequestMessageProperty)
Create a copy of the provided HttpRequestMessageProperty.
Declaration
public static HttpRequestMessageProperty Clone(this HttpRequestMessageProperty property)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpRequestMessageProperty | property | Message property to be cloned. |
Returns
| Type | Description |
|---|---|
| HttpRequestMessageProperty | Deep copy of the provided HttpRequestMessageProperty. |
Clone(HttpResponseMessageProperty)
Create a copy of the provided HttpResponseMessageProperty.
Declaration
public static HttpResponseMessageProperty Clone(this HttpResponseMessageProperty property)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpResponseMessageProperty | property | Message property to be cloned. |
Returns
| Type | Description |
|---|---|
| HttpResponseMessageProperty | Deep copy of the provided HttpResponseMessageProperty. |
CreateMessage(MessageVersion, string)
Creates SOAP or RESTful message from the provided content.
Declaration
[SuppressMessage("Microsoft.Reliability", "CA2000: Dispose objects before losing scope")]
public static Message CreateMessage(MessageVersion version, string content)
Parameters
| Type | Name | Description |
|---|---|---|
| MessageVersion | version | Version of the message to be constructed. |
| string | content | String representing the body content of the message. |
Returns
| Type | Description |
|---|---|
| Message | Constructed message. |
CreateNullMessage()
Creates and returns a RESTful message without body content.
Declaration
public static Message CreateNullMessage()
Returns
| Type | Description |
|---|---|
| Message | RESTful message without body content. |
GetClientAddress(Message)
Retrieves caller's IP address from provided message.
Declaration
public static string GetClientAddress(this Message message)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Request message which may contain caller's IP address. |
Returns
| Type | Description |
|---|---|
| string | Caller's IP address or Null, if not TCP-based transport was used or message is outbound. |
GetHttpHeader(Message, bool, string)
Returns the value of the specified HTTP header.
Declaration
public static string GetHttpHeader(this Message message, bool isRequest, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Request or response message to extract HTTP header from. |
| bool | isRequest | Flag indicating that provided message is the request message. If False then provided message is the response message. |
| string | name | Name of the HTTP header. |
Returns
| Type | Description |
|---|---|
| string | Value of the specified HTTP header or Null, if header is not found. |
GetHttpHeaders(Message, bool)
Retrieves transport level HTTP headers from provided message.
Declaration
public static IDictionary<string, string> GetHttpHeaders(this Message message, bool isRequest)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Message containing the HTTP headers. |
| bool | isRequest | Flag indicating that provided message is the request message. If False then provided message is the response message. |
Returns
| Type | Description |
|---|---|
| IDictionary<string, string> | Name/value collection populated with HTTP headers. |
GetHttpMethod(Message)
Returns the request HTTP method/action extracted from the provided request message.
Declaration
public static string GetHttpMethod(this Message message)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Request message to extract HTTP method from. |
Returns
| Type | Description |
|---|---|
| string | HTTP method/action contained in the provided message or Null, if provided message is not an HTTP request message. |
GetHttpRequestMessageProperty(Message, bool)
Extracts HttpRequestMessageProperty from provided request message.
Declaration
public static HttpRequestMessageProperty GetHttpRequestMessageProperty(this Message message, bool createIfNotFound)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Message where to look for the message property. |
| bool | createIfNotFound | Flag indicating that if property is not found, it has to be created and added to the message. |
Returns
| Type | Description |
|---|---|
| HttpRequestMessageProperty | Message property extracted from the message. |
GetHttpRequestMessageProperty(MessageProperties, bool)
Extracts HttpRequestMessageProperty from provided request message properties.
Declaration
public static HttpRequestMessageProperty GetHttpRequestMessageProperty(this MessageProperties properties, bool createIfNotFound)
Parameters
| Type | Name | Description |
|---|---|---|
| MessageProperties | properties | Message properties collection where to look for the message property. |
| bool | createIfNotFound | Flag indicating that if property is not found, it has to be created and added to the message properties. |
Returns
| Type | Description |
|---|---|
| HttpRequestMessageProperty | Message property extracted from the message properties collection. |
GetHttpResponseMessageProperty(Message, bool)
Extracts HttpResponseMessageProperty from provided response message.
Declaration
public static HttpResponseMessageProperty GetHttpResponseMessageProperty(this Message message, bool createIfNotFound)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Message where to look for the message property. |
| bool | createIfNotFound | Flag indicating that if property is not found, it has to be created and added to the message. |
Returns
| Type | Description |
|---|---|
| HttpResponseMessageProperty | Message property extracted from the message. |
GetHttpResponseMessageProperty(MessageProperties, bool, bool)
Extracts HttpResponseMessageProperty from provided response message properties.
Declaration
[SuppressMessage("Microsoft.Design", "CA1026: Default parameters should not be used")]
public static HttpResponseMessageProperty GetHttpResponseMessageProperty(this MessageProperties properties, bool createIfNotFound, bool isFault = false)
Parameters
| Type | Name | Description |
|---|---|---|
| MessageProperties | properties | Message properties collection where to look for the message property. |
| bool | createIfNotFound | Flag indicating that if property is not found, it has to be created and added to the message properties. |
| bool | isFault | Flag indicating that properties belong to a fault message. |
Returns
| Type | Description |
|---|---|
| HttpResponseMessageProperty | Message property extracted from the message properties collection. |
GetHttpStatusCode(Message)
Returns the HTTP status code extracted from the provided response message.
Declaration
public static HttpStatusCode? GetHttpStatusCode(this Message message)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Response message to extract HTTP status code from. |
Returns
| Type | Description |
|---|---|
| HttpStatusCode? | HTTP status code extracted from the provided response message or Null, if provided message is not an HTTP response message. |
GetMessageContent(ref Message, bool, bool)
Extracts message content into a string taking care about empty messages, read messages, and binary encoded messages.
Declaration
[SuppressMessage("Microsoft.Usage", "CA2202: Do not dispose objects multiple times")]
[SuppressMessage("Microsoft.Design", "CA1045: Do not pass types by reference")]
public static string GetMessageContent(ref Message message, bool preserveMessage, bool returnBodyContent)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Message which content needs to be extracted. |
| bool | preserveMessage | Flag indicating that provided message must be preserved (returned with Created state) after reading. |
| bool | returnBodyContent | Flag indicating that message body content must be returned. If False then whole message including SOAP envelope is returned. |
Returns
| Type | Description |
|---|---|
| string | The message content. |
GetRawMessageContent(ref Message)
Extracts the message content into an array of bytes taking care about empty messages, read messages, and binary encoded messages.
Declaration
[SuppressMessage("Microsoft.Usage", "CA2202: Do not dispose objects multiple times")]
[SuppressMessage("Microsoft.Design", "CA1045: Do not pass types by reference")]
public static byte[] GetRawMessageContent(ref Message message)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Message which content needs to be extracted. |
Returns
| Type | Description |
|---|---|
| byte[] | The message content. |
GetRequestUri(Message)
Returns the request URI from the provided request message.
Declaration
public static Uri GetRequestUri(this Message message)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Request message to extract HTTP request URI from. |
Returns
| Type | Description |
|---|---|
| Uri | Request URI or message destination address. |
IsEmptyMessage(Message)
Returns flag indicating whether the provided message's content is empty.
Declaration
public static bool IsEmptyMessage(this Message message)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Message to be examined. |
Returns
| Type | Description |
|---|---|
| bool | True, if message content is empty. False, otherwise. |
IsFaultOrHttpError(Message)
Returns flag indicating that message contains SOAP fault or its HTTP status code indicates a failure.
Declaration
public static bool IsFaultOrHttpError(this Message message)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Response message to be inspected. |
Returns
| Type | Description |
|---|---|
| bool | True, if message contains SOAP fault or its HTTP status code indicates a failure. False, otherwise. |
IsRawMessage(Message)
Returns flag indicating whether the provided message uses Raw or Base64-encoded body format.
Declaration
public static bool IsRawMessage(this Message message)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Message to be examined. |
Returns
| Type | Description |
|---|---|
| bool | True, if message content is Base64-encoded. False, otherwise. |
RemoveHttpHeader(Message, bool, string)
Removes the specified HTTP header from the provided message.
Declaration
public static void RemoveHttpHeader(this Message message, bool isRequest, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Request or response message to remove HTTP header from. |
| bool | isRequest | Flag indicating that provided message is the request message. If False then provided message is the response message. |
| string | name | Name of the HTTP header to be removed. |
SetHttpHeader(Message, bool, string, string, ExistingValueAction)
Adds or replaces HTTP header with the specified name and value.
Declaration
public static void SetHttpHeader(this Message message, bool isRequest, string name, string value, ExistingValueAction action)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Request or response message to add HTTP header to. |
| bool | isRequest | Flag indicating that provided message is the request message. If False then provided message is the response message. |
| string | name | Name of the HTTP header. |
| string | value | Value of the HTTP header. |
| ExistingValueAction | action | Action to be taken if the specified header already exists in the provided message. |
SetHttpMethod(Message, string)
Sets or replaces HTTP method/action in the provided request message.
Declaration
public static void SetHttpMethod(this Message message, string method)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Request message where HTTP method/action needs to be set. |
| string | method | HTTP method/action to be set. |
SetHttpStatusCode(Message, HttpStatusCode, string)
Sets or replaces an HTTP status code in the provided response message.
Declaration
public static void SetHttpStatusCode(this Message message, HttpStatusCode code, string description)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Response message where HTTP status code needs to be set. |
| HttpStatusCode | code | HTTP status code to be set. |
| string | description | HTTP status code description to be set. |
SetMessageBodyContent(Message, string)
Creates a copy of the message with the specified message content.
Declaration
[SuppressMessage("Microsoft.Reliability", "CA2000: Dispose objects before losing scope")]
public static Message SetMessageBodyContent(Message originalMessage, string content)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | originalMessage | Original message to be copied. |
| string | content | Content to be used for the new message. |
Returns
| Type | Description |
|---|---|
| Message | New message containing the original's message version and headers and provided content. |
SetMessageBodyContent(Message, XmlReader)
Creates a copy of the message with the specified XML content.
Declaration
[SuppressMessage("Microsoft.Reliability", "CA2000: Dispose objects before losing scope")]
public static Message SetMessageBodyContent(Message originalMessage, XmlReader contentReader)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | originalMessage | Original message to be copied. |
| XmlReader | contentReader | XML reader to the content to be used for the new message. |
Returns
| Type | Description |
|---|---|
| Message | New message containing the original's message version and headers and provided content. |
SetRequestUri(Message, Uri)
Sets or replaces the request URI or destination address in the provided request message.
Declaration
public static void SetRequestUri(this Message message, Uri requestUri)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | Request message where destination address needs to be set. |
| Uri | requestUri | Request URI or destination address to be set. |