Export (0) Print
Expand All

MessageEncoder.IsContentTypeSupported Method

Returns a value that indicates whether a specified message-level content-type value is supported by the message encoder.

Namespace:  System.ServiceModel.Channels
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public virtual bool IsContentTypeSupported(
	string contentType
)

Parameters

contentType
Type: System.String

The message-level content-type being tested.

Return Value

Type: System.Boolean
true if the message-level content-type specified is supported; otherwise false.

This method is used to determine whether the message encoder can be used to read a particular style of message, based on its content-type. The information in the ContentType class is used to describe the data that is contained in a message and is used to determine if there is a content-type match.

A grammar that details the syntax of the content-type header is described in RFC 2045 Section 5.1. RFC 2046 provides detailed information on Multipurpose Internet Mail Extensions (MIME) media types and their parameters.

The following code example shows how to override this method to handle different content types with the same media type.

public override bool IsContentTypeSupported(string contentType) 
{ 
    if (base.IsContentTypeSupported(contentType)) 
    { 
        return true; 
    } 
    if (contentType.Length == this.MediaType.Length) 
    { 
        return contentType.Equals(this.MediaType, StringComparison.OrdinalIgnoreCase); 
    } 
    else 
    { 
        if (contentType.StartsWith(this.MediaType, StringComparison.OrdinalIgnoreCase) 
            && (contentType[this.MediaType.Length] == ';')) 
        { 
            return true; 
        } 
    } 
    return false; 
}
public class CustomTextMessageEncoderFactory : MessageEncoderFactory
{
    private MessageEncoder encoder;
    private MessageVersion version;
    private string mediaType;
    private string charSet;

    internal CustomTextMessageEncoderFactory(string mediaType, string charSet,
        MessageVersion version)
    {
        this.version = version;
        this.mediaType = mediaType;
        this.charSet = charSet;
        this.encoder = new CustomTextMessageEncoder(this);
    }

    public override MessageEncoder Encoder
    {
        get 
        { 
            return this.encoder;
        }
    }

    public override MessageVersion MessageVersion
    {
        get 
        { 
            return this.version;
        }
    }

    internal string MediaType
    {
        get
        {
            return this.mediaType;
        }
    }

    internal string CharSet
    {
        get
        {
            return this.charSet;
        }
    }
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft