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();
}
Is there a way to do the reverse? Given a IEdmModel
generate the metadata document?
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.