本文整理汇总了C#中Microsoft.OData.Core.ODataMessageWriterSettings.SetMetadataDocumentUri方法的典型用法代码示例。如果您正苦于以下问题:C# ODataMessageWriterSettings.SetMetadataDocumentUri方法的具体用法?C# ODataMessageWriterSettings.SetMetadataDocumentUri怎么用?C# ODataMessageWriterSettings.SetMetadataDocumentUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Core.ODataMessageWriterSettings
的用法示例。
在下文中一共展示了ODataMessageWriterSettings.SetMetadataDocumentUri方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateJsonLightSettings
private static ODataMessageWriterSettings CreateJsonLightSettings()
{
ODataMessageWriterSettings settings = new ODataMessageWriterSettings();
settings.SetContentType(ODataFormat.Json);
settings.SetMetadataDocumentUri(CreateFakeUri());
return settings;
}
示例2: WriteToStream
private void WriteToStream(Type type, object value, Stream writeStream, HttpContent content, HttpContentHeaders contentHeaders)
{
IEdmModel model = Request.GetEdmModel();
if (model == null)
{
throw Error.InvalidOperation(SRResources.RequestMustHaveModel);
}
ODataSerializer serializer = GetSerializer(type, value, model, _serializerProvider);
UrlHelper urlHelper = Request.GetUrlHelper() ?? new UrlHelper(Request);
ODataPath path = Request.GetODataPath();
IEdmEntitySet targetEntitySet = path == null ? null : path.EntitySet;
// serialize a response
HttpConfiguration configuration = Request.GetConfiguration();
if (configuration == null)
{
throw Error.InvalidOperation(SRResources.RequestMustContainConfiguration);
}
IODataResponseMessage responseMessage = new ODataMessageWrapper(writeStream, content.Headers);
ODataMessageWriterSettings writerSettings = new ODataMessageWriterSettings(MessageWriterSettings)
{
BaseUri = GetBaseAddress(Request),
Version = _version,
};
// The MetadataDocumentUri is never required for errors. Additionally, it sometimes won't be available
// for errors, such as when routing itself fails. In that case, the route data property is not
// available on the request, and due to a bug with HttpRoute.GetVirtualPath (bug #669) we won't be able
// to generate a metadata link.
if (serializer.ODataPayloadKind != ODataPayloadKind.Error)
{
string metadataLink = urlHelper.ODataLink(new MetadataPathSegment());
if (metadataLink == null)
{
throw new SerializationException(SRResources.UnableToDetermineMetadataUrl);
}
string resourcePath = path != null ? path.ToString() : String.Empty;
writerSettings.SetMetadataDocumentUri(
new Uri(metadataLink),
Request.GetSelectExpandClause(),
resourcePath,
isIndividualProperty: false);
}
MediaTypeHeaderValue contentType = null;
if (contentHeaders != null && contentHeaders.ContentType != null)
{
contentType = contentHeaders.ContentType;
}
using (ODataMessageWriter messageWriter = new ODataMessageWriter(responseMessage, writerSettings, model))
{
ODataSerializerContext writeContext = new ODataSerializerContext()
{
Request = Request,
RequestContext = Request.GetRequestContext(),
Url = urlHelper,
EntitySet = targetEntitySet,
Model = model,
RootElementName = GetRootElementName(path) ?? "root",
SkipExpensiveAvailabilityChecks = serializer.ODataPayloadKind == ODataPayloadKind.Feed,
Path = path,
MetadataLevel = ODataMediaTypes.GetMetadataLevel(contentType),
SelectExpandClause = Request.GetSelectExpandClause()
};
serializer.WriteObject(value, type, messageWriter, writeContext);
}
}