private static ODataInputFormatter CreateFormatterWithoutMediaTypes(params ODataPayloadKind[] payloadKinds)
        {
            ODataInputFormatter formatter = new ODataInputFormatter(payloadKinds);

            AddSupportedEncodings(formatter);
            return(formatter);
        }
        private static ODataInputFormatter CreateApplicationJson()
        {
            ODataInputFormatter formatter = CreateFormatterWithoutMediaTypes(
                ODataPayloadKind.ResourceSet,
                ODataPayloadKind.Resource,
                ODataPayloadKind.Property,
                ODataPayloadKind.EntityReferenceLink,
                ODataPayloadKind.EntityReferenceLinks,
                ODataPayloadKind.Collection,
                ODataPayloadKind.ServiceDocument,
                ODataPayloadKind.Error,
                ODataPayloadKind.Parameter,
                ODataPayloadKind.Delta);

            // Add minimal metadata as the first media type so it gets used when the request doesn't
            // ask for a specific content type
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataMinimalMetadataStreamingTrue);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataMinimalMetadataStreamingFalse);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataMinimalMetadata);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataFullMetadataStreamingTrue);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataFullMetadataStreamingFalse);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataFullMetadata);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataNoMetadataStreamingTrue);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataNoMetadataStreamingFalse);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonODataNoMetadata);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonStreamingTrue);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJsonStreamingFalse);
            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationJson);

            return(formatter);
        }
        private static ODataInputFormatter CreateRawValue()
        {
            ODataInputFormatter formatter = CreateFormatterWithoutMediaTypes(ODataPayloadKind.Value);

            formatter.SupportedMediaTypes.Add("text/plain");
            return(formatter);
        }
        private static void AddSupportedEncodings(ODataInputFormatter formatter)
        {
            formatter.SupportedEncodings.Add(new UTF8Encoding(encoderShouldEmitUTF8Identifier: false,
                                                              throwOnInvalidBytes: true));

            formatter.SupportedEncodings.Add(new UnicodeEncoding(bigEndian: false, byteOrderMark: true,
                                                                 throwOnInvalidBytes: true));
        }
        private static ODataInputFormatter CreateApplicationXml()
        {
            ODataInputFormatter formatter = CreateFormatterWithoutMediaTypes(
                ODataPayloadKind.MetadataDocument);

            formatter.SupportedMediaTypes.Add(ODataMediaTypes.ApplicationXml);

            return(formatter);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Internal method used for selecting the base address to be used with OData uris.
 /// If the consumer has provided a delegate for overriding our default implementation,
 /// we call that, otherwise we default to existing behavior below.
 /// </summary>
 /// <param name="request">The HttpRequest object for the given request.</param>
 /// <returns>The base address to be used as part of the service root; must terminate with a trailing '/'.</returns>
 private Uri GetBaseAddressInternal(HttpRequest request)
 {
     if (BaseAddressFactory != null)
     {
         return(BaseAddressFactory(request));
     }
     else
     {
         return(ODataInputFormatter.GetDefaultBaseAddress(request));
     }
 }