Show / Hide Table of Contents

    Class MessageHelper

    Provides extension helper methods for working with WCF messages.

    Inheritance
    Object
    MessageHelper
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    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
    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
    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, 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
    Message message

    Request or response message to extract HTTP header from.

    Boolean 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, 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
    Message message

    Message containing the HTTP headers.

    Boolean 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, Boolean)

    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.

    Boolean 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, Boolean)

    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.

    Boolean 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, Boolean)

    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.

    Boolean 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, Boolean, Boolean)

    Extracts HttpResponseMessageProperty from provided response message properties.

    Declaration
    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.

    Boolean createIfNotFound

    Flag indicating that if property is not found, it has to be created and added to the message properties.

    Boolean 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
    Nullable<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
    Message message

    Message which content needs to be extracted.

    Boolean preserveMessage

    Flag indicating that provided message must be preserved (returned with Created state) after reading.

    Boolean 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.

    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
    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
    Message message

    Response message to be inspected.

    Returns
    Type Description
    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 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
    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
    Message message

    Request or response message to remove HTTP header from.

    Boolean 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, 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
    Message message

    Request or response message to add HTTP header to.

    Boolean 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
    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
    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.

    Back to top Nevatech Sentinet 6.5 Online Documentation