Ejemplo n.º 1
0
            WebContentFormat GetFormatForContentType(string contentType)
            {
                WebContentFormat messageFormat;

                if (TryGetContentTypeMapping(contentType, out messageFormat) &&
                    (messageFormat != WebContentFormat.Default))
                {
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        if (string.IsNullOrEmpty(contentType))
                        {
                            contentType = "<null>";
                        }
                        TraceUtility.TraceEvent(TraceEventType.Information,
                                                TraceCode.RequestFormatSelectedFromContentTypeMapper,
                                                SR2.GetString(SR2.TraceCodeRequestFormatSelectedFromContentTypeMapper, messageFormat.ToString(), contentType));
                    }
                    return(messageFormat);
                }

                // Don't pass on null content types to IsContentTypeSupported methods -- they might throw.
                // If null content type isn't already mapped, return the default format of Raw.

                if (contentType == null)
                {
                    messageFormat = WebContentFormat.Raw;
                }
                else if (JsonMessageEncoder.IsContentTypeSupported(contentType))
                {
                    messageFormat = WebContentFormat.Json;
                }
                else if (TextMessageEncoder.IsContentTypeSupported(contentType))
                {
                    messageFormat = WebContentFormat.Xml;
                }
                else
                {
                    messageFormat = WebContentFormat.Raw;
                }

                if (DiagnosticUtility.ShouldTraceInformation)
                {
                    TraceUtility.TraceEvent(TraceEventType.Information,
                                            TraceCode.RequestFormatSelectedByEncoderDefaults,
                                            SR2.GetString(SR2.TraceCodeRequestFormatSelectedByEncoderDefaults, messageFormat.ToString(), contentType));
                }

                return(messageFormat);
            }
Ejemplo n.º 2
0
            public override bool IsContentTypeSupported(string contentType)
            {
                if (contentType == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contentType");
                }

                WebContentFormat messageFormat;

                if (TryGetContentTypeMapping(contentType, out messageFormat) &&
                    (messageFormat != WebContentFormat.Default))
                {
                    return(true);
                }

                return(RawMessageEncoder.IsContentTypeSupported(contentType) || JsonMessageEncoder.IsContentTypeSupported(contentType) || TextMessageEncoder.IsContentTypeSupported(contentType));
            }