[英]Fetching $metadata for a specific collection or entity with Odata web services in Microsoft Dynamics NAV 2016
As part of an integration project, I need a PHP website to be able to both read from and write to Microsoft Dynamics NAV 2016's Odata services.作为集成项目的一部分,我需要一个能够读取和写入 Microsoft Dynamics NAV 2016 的 Odata 服务的 PHP 网站。
Microsoft Dynamics NAV 2016 uses the Odata v3 standard . Microsoft Dynamics NAV 2016 使用Odata v3 标准。
Now, let's take my customer
service as an example.现在,让我们以我的
customer
服务为例。
Fetching an overview of my collection of customer
entities works fine, using a link with the following format :使用以下格式的链接获取我的
customer
实体集合的概述可以正常工作:
https://<Server>:<WebServicePort>/<ServerInstance>/OData/Company(\'<CompanyName>\')/customer
Fetching a single customer
entity based on id
works fine, using a link with the following format :使用具有以下格式的链接,基于
id
获取单个customer
实体可以正常工作:
https://<Server>:<WebServicePort>/<ServerInstance>/OData/Company(\'<CompanyName>\')/customer(\'<Id>\')
Getting an overview of the $metadata
for all of my services works fine (although it's lacking Json support), using a link with the following format :使用以下格式的链接获取我所有服务的
$metadata
概览可以正常工作(尽管它缺乏 Json 支持):
https://<Server>:<WebServicePort>/<ServerInstance>/OData/$metadata
Now, based on both the Odata v3 specs and the value of the odata.metadata
property of my customer overview service, I would expect to be able to get an overview of the $metadata
of the customer
entity, using a link with the following format :现在,基于 Odata v3 规范和我的客户概览服务的
odata.metadata
属性的值,我希望能够使用具有以下格式的链接获得customer
实体的$metadata
的概览:
https://<Server>:<WebServicePort>/<ServerInstance>/OData/$metadata#customer
This doesn't work as expected.这不能按预期工作。 See sub-section
The issue
below.请参阅下面
The issue
小节。
Similarly, based on both the Odata v3 specs and the value of the odata.metadata
property of my dataset when retrieving a single customer, I would expect to be able to get an overview of the $metadata
of a single field of the customer
entity, using a link with this format :同样,在检索单个客户时,基于 Odata v3 规范和我的数据集的
odata.metadata
属性的值,我希望能够获得customer
实体单个字段的$metadata
的概述,使用这种格式的链接:
https://<Server>:<WebServicePort>/<ServerInstance>/OData/$metadata#customer/@<FieldName>
This doesn't work as expected.这不能按预期工作。 See sub-section
The issue
below.请参阅下面
The issue
小节。
For some reason, everything following $metadata
appears to be ignored.出于某种原因,
$metadata
之后的所有内容似乎都被忽略了。 This means that the last three URLs give me the exact same output, which is not what I expected.这意味着最后三个 URL 给了我完全相同的输出,这不是我所期望的。
Fetching collection-specific metadata
and Fetching entity-specific metadata
of my The context
section hereabove?Fetching collection-specific metadata
”和“ Fetching entity-specific metadata
”的子部分The context
尝试的那样?As @xuzhg suggested in the comments and as is indicated by Github issues like Support Metadata as a service (#181) , it appears that the Odata $metadata
are not really a dynamic service.正如@xuzhg在评论中所建议的那样,正如支持元数据即服务 (#181)等 Github 问题所表明的那样,Odata
$metadata
似乎并不是真正的动态服务。 Instead, it's just a single XML file.相反,它只是一个 XML 文件。
This explains not only why anything after $metadata is ignored in links of format https://<Server>:<WebServicePort>/<ServerInstance>/OData/$metadata#...
, but also why it only supports XML, and not Json (unlike actual Odata services).这不仅解释了为什么在格式
https://<Server>:<WebServicePort>/<ServerInstance>/OData/$metadata#...
的链接中忽略 $metadata 之后的任何内容,而且解释了为什么它只支持 XML,而不支持Json(与实际的 Odata 服务不同)。
Since the specific metadata you want is identified by a fragment appended to the metadata URI, you must fetch the entire $metadata
document and then dereference the fragment on the client.由于您想要的特定元数据由附加到元数据 URI 的片段标识,因此您必须获取整个
$metadata
文档,然后在客户端取消引用该片段。
The good news is that the fragment dereferencing is pretty straightforward.好消息是片段解引用非常简单。 A fragment like
#customer
specifies an EntityType
element whose Name
attribute has the value customer
. #customer
类的片段指定了一个EntityType
元素,其Name
属性的值为customer
。 Similarly, #customer/@someprop
maps to a Property
element whose Name
attribute is someprop
.同样,
#customer/@someprop
映射到Name
属性为someprop
的Property
元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.