Class MessageHelper
Provides extension helper methods for working with WCF messages.
Inheritance
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
public static Message ChangeMessageVersion(this Message message, MessageVersion targetVersion)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceModel.Channels.Message | message | Original message that needs to converted. |
System.ServiceModel.Channels.MessageVersion | targetVersion | Message version of the converted message. |
Returns
Type | Description |
---|---|
System.ServiceModel.Channels.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 System.ServiceModel.Channels.HttpRequestMessageProperty.
Declaration
public static HttpRequestMessageProperty Clone(this HttpRequestMessageProperty property)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceModel.Channels.HttpRequestMessageProperty | property | Message property to be cloned. |
Returns
Type | Description |
---|---|
System.ServiceModel.Channels.HttpRequestMessageProperty | Deep copy of the provided System.ServiceModel.Channels.HttpRequestMessageProperty. |
Clone(HttpResponseMessageProperty)
Create a copy of the provided System.ServiceModel.Channels.HttpResponseMessageProperty.
Declaration
public static HttpResponseMessageProperty Clone(this HttpResponseMessageProperty property)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceModel.Channels.HttpResponseMessageProperty | property | Message property to be cloned. |
Returns
Type | Description |
---|---|
System.ServiceModel.Channels.HttpResponseMessageProperty | Deep copy of the provided System.ServiceModel.Channels.HttpResponseMessageProperty. |
CreateMessage(MessageVersion, String)
Creates SOAP or RESTful message from the provided content.
Declaration
public static Message CreateMessage(MessageVersion version, string content)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceModel.Channels.MessageVersion | version | Version of the message to be constructed. |
System.String | content | String representing the body content of the message. |
Returns
Type | Description |
---|---|
System.ServiceModel.Channels.Message | Constructed message. |
CreateNullMessage()
Creates and returns a RESTful message without body content.
Declaration
public static Message CreateNullMessage()
Returns
Type | Description |
---|---|
System.ServiceModel.Channels.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 |
---|---|---|
System.ServiceModel.Channels.Message | message | Request message which may contain caller's IP address. |
Returns
Type | Description |
---|---|
System.String | Caller's IP address or Null, if not TCP-based transport was used or message is outbound. |
GetHttpHeader(Message, Boolean, 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 |
---|---|---|
System.ServiceModel.Channels.Message | message | Request or response message to extract HTTP header from. |
System.Boolean | isRequest | Flag indicating that provided message is the request message. If False then provided message is the response message. |
System.String | name | Name of the HTTP header. |
Returns
Type | Description |
---|---|
System.String | Value of the specified HTTP header or Null, if header is not found. |
GetHttpHeaders(Message, Boolean)
Retrieves transport level HTTP headers from provided message.
Declaration
public static IDictionary<string, string> GetHttpHeaders(this Message message, bool isRequest)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceModel.Channels.Message | message | Message containing the HTTP headers. |
System.Boolean | isRequest | Flag indicating that provided message is the request message. If False then provided message is the response message. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.String, System.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 |
---|---|---|
System.ServiceModel.Channels.Message | message | Request message to extract HTTP method from. |
Returns
Type | Description |
---|---|
System.String | HTTP method/action contained in the provided message or Null, if provided message is not an HTTP request message. |
GetHttpRequestMessageProperty(Message, Boolean)
Extracts System.ServiceModel.Channels.HttpRequestMessageProperty from provided request message.
Declaration
public static HttpRequestMessageProperty GetHttpRequestMessageProperty(this Message message, bool createIfNotFound)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceModel.Channels.Message | message | Message where to look for the message property. |
System.Boolean | createIfNotFound | Flag indicating that if property is not found, it has to be created and added to the message. |
Returns
Type | Description |
---|---|
System.ServiceModel.Channels.HttpRequestMessageProperty | Message property extracted from the message. |
GetHttpRequestMessageProperty(MessageProperties, Boolean)
Extracts System.ServiceModel.Channels.HttpRequestMessageProperty from provided request message properties.
Declaration
public static HttpRequestMessageProperty GetHttpRequestMessageProperty(this MessageProperties properties, bool createIfNotFound)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceModel.Channels.MessageProperties | properties | Message properties collection where to look for the message property. |
System.Boolean | createIfNotFound | Flag indicating that if property is not found, it has to be created and added to the message properties. |
Returns
Type | Description |
---|---|
System.ServiceModel.Channels.HttpRequestMessageProperty | Message property extracted from the message properties collection. |
GetHttpResponseMessageProperty(Message, Boolean)
Extracts System.ServiceModel.Channels.HttpResponseMessageProperty from provided response message.
Declaration
public static HttpResponseMessageProperty GetHttpResponseMessageProperty(this Message message, bool createIfNotFound)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceModel.Channels.Message | message | Message where to look for the message property. |
System.Boolean | createIfNotFound | Flag indicating that if property is not found, it has to be created and added to the message. |
Returns
Type | Description |
---|---|
System.ServiceModel.Channels.HttpResponseMessageProperty | Message property extracted from the message. |
GetHttpResponseMessageProperty(MessageProperties, Boolean, Boolean)
Extracts System.ServiceModel.Channels.HttpResponseMessageProperty from provided response message properties.
Declaration
public static HttpResponseMessageProperty GetHttpResponseMessageProperty(this MessageProperties properties, bool createIfNotFound, bool isFault = false)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceModel.Channels.MessageProperties | properties | Message properties collection where to look for the message property. |
System.Boolean | createIfNotFound | Flag indicating that if property is not found, it has to be created and added to the message properties. |
System.Boolean | isFault | Flag indicating that properties belong to a fault message. |
Returns
Type | Description |
---|---|
System.ServiceModel.Channels.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 |
---|---|---|
System.ServiceModel.Channels.Message | message | Response message to extract HTTP status code from. |
Returns
Type | Description |
---|---|
System.Nullable<System.Net.HttpStatusCode> | HTTP status code extracted from the provided response message or Null, if provided message is not an HTTP response message. |
GetMessageContent(ref Message, Boolean, Boolean)
Extracts message content into a string taking care about empty messages, read messages, and binary encoded messages.
Declaration
public static string GetMessageContent(ref Message message, bool preserveMessage, bool returnBodyContent)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceModel.Channels.Message | message | Message which content needs to be extracted. |
System.Boolean | preserveMessage | Flag indicating that provided message must be preserved (returned with System.ServiceModel.Channels.MessageState.Created state) after reading. |
System.Boolean | returnBodyContent | Flag indicating that message body content must be returned. If False then whole message including SOAP envelope is returned. |
Returns
Type | Description |
---|---|
System.String | 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 |
---|---|---|
System.ServiceModel.Channels.Message | message | Request message to extract HTTP request URI from. |
Returns
Type | Description |
---|---|
System.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 |
---|---|---|
System.ServiceModel.Channels.Message | message | Message to be examined. |
Returns
Type | Description |
---|---|
System.Boolean | 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 |
---|---|---|
System.ServiceModel.Channels.Message | message | Response message to be inspected. |
Returns
Type | Description |
---|---|
System.Boolean | 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 System.ServiceModel.Channels.WebContentFormat.Raw or Base64-encoded body format.
Declaration
public static bool IsRawMessage(this Message message)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceModel.Channels.Message | message | Message to be examined. |
Returns
Type | Description |
---|---|
System.Boolean | True, if message content is Base64-encoded. False, otherwise. |
RemoveHttpHeader(Message, Boolean, 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 |
---|---|---|
System.ServiceModel.Channels.Message | message | Request or response message to remove HTTP header from. |
System.Boolean | isRequest | Flag indicating that provided message is the request message. If False then provided message is the response message. |
System.String | name | Name of the HTTP header to be removed. |
SetHttpHeader(Message, Boolean, 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 |
---|---|---|
System.ServiceModel.Channels.Message | message | Request or response message to add HTTP header to. |
System.Boolean | isRequest | Flag indicating that provided message is the request message. If False then provided message is the response message. |
System.String | name | Name of the HTTP header. |
System.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 |
---|---|---|
System.ServiceModel.Channels.Message | message | Request message where HTTP method/action needs to be set. |
System.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 |
---|---|---|
System.ServiceModel.Channels.Message | message | Response message where HTTP status code needs to be set. |
System.Net.HttpStatusCode | code | HTTP status code to be set. |
System.String | description | HTTP status code description to be set. |
SetMessageBodyContent(Message, String)
Creates a copy of the message with the specified message content.
Declaration
public static Message SetMessageBodyContent(Message originalMessage, string content)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceModel.Channels.Message | originalMessage | Original message to be copied. |
System.String | content | Content to be used for the new message. |
Returns
Type | Description |
---|---|
System.ServiceModel.Channels.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
public static Message SetMessageBodyContent(Message originalMessage, XmlReader contentReader)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceModel.Channels.Message | originalMessage | Original message to be copied. |
System.Xml.XmlReader | contentReader | XML reader to the content to be used for the new message. |
Returns
Type | Description |
---|---|
System.ServiceModel.Channels.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 |
---|---|---|
System.ServiceModel.Channels.Message | message | Request message where destination address needs to be set. |
System.Uri | requestUri | Request URI or destination address to be set. |