本文介绍了OData:从IEdmModel生成$ metadata文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下内容从$ metadata文档生成IEdmModel:

I can generate an IEdmModel from a $metadata document with something like this:

HttpWebRequest request = HttpWebRequest.CreateHttp("http://services.odata.org/v3/odata/OData.svc/$metadata");
ClientHttpResponseMessage metadataMessage = new ClientHttpResponseMessage((HttpWebResponse)request.GetResponse());
using (var messageReader = new ODataMessageReader(metadataMessage))
{
    IEdmModel model = messageReader.ReadMetadataDocument();
}

有没有办法做相反的事情?给定IEdmModel生成元数据文档?

Is there a way to do the reverse? Given a IEdmModel generate the metadata document?

推荐答案

是的,您可以使用odl writer从IEdmModel中写入元数据.ODataMessageWriter类具有功能WriteMetadataDocument.假设您具有IEdmModel模型,则可以使用以下代码将元数据写入消息中.

Yes, you can use odl writer to write the metadata from IEdmModel. Class ODataMessageWriter have function WriteMetadataDocument. Assuming you have IEdmModel model, you can use following code to write metadata to message.

using (var msgWriter = new ODataMessageWriter((IODataResponseMessage)message, writerSettings, model))
{
  msgWriter.WriteMetadataDocument();
}

这篇关于OData:从IEdmModel生成$ metadata文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 00:59