I have a WebService that expose this $metadata
:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0"> > <edmx:DataServices m:DataServiceVersion="1.0"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<Schema xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://schemas.microsoft.com/ado/2007/05/edm"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
Namespace="NAV">
<EntityType Name="PAsset">
<Key> <PropertyRef Name="No"/> </Key> <Property Name="No" Nullable="false" Type="Edm.String"/> <Property Name="Description"
Nullable="true" Type="Edm.String"/> <Property Name="Inactive"
Nullable="false" Type="Edm.Boolean"/> <Property Name="Insured"
Nullable="false" Type="Edm.Boolean"/> </EntityType>
<EntityType Name="PAssetsDepreciationBook">
<EntityType Name="PBankAPostGrp">
<EntityType Name="PCompany">
<EntityType Name="PCustomer">
Is possible get the information in this $metadata
in a C# aplication?
I Have a Application with a reference to the Service working, and some code i'm using:
uriString = String.Format("PAssetsDepreciationBook?$filter=FA_No eq '{0}'",cliente);
contex = new ServiceReference1.NAV(new Uri(serviceEndPoint)); contex.Credentials = CredentialCache.DefaultCredentials;
var customers = contex.Execute(new Uri(uriString, UriKind.Relative));
foreach (var c in customers) { result = result + c.Acquisition_Cost; } return result;
This works fine, but to get $metadata
doesn't.
Thanks, it work just fine.
Just like this:
After this, just parse the data like a xml file.
There is already code (mostly) to do this. It involves the ODataMessageReader.ReadMetadataDocument() call:
You need the ClientHttpResponseMessage class but that is simple (from ODataLib101):
With the IEdmModel, you can access all the information in the metadata to do things like build a dictionary of type->controller name:
The FindType() call in the middle of the LINQ chain above simply searches all assemblies for a type given the type name:
You can request the metadata as a plain XML using
HttpWebRequest
for example. If you need to parse it, you can useEdmLib
(Microsoft.Data.Edm.dll
) which can be found onNuGet
or even betterODataLib
(Microsoft.Data.OData.dll
) also onNuget
which hasODataMessageReader
.ReadMetadataDocument
specifically designed to read these (it still returns the EDM object model for it, it just deals with theEDMX
wrapper and versioning for you).