问题描述
作为集成项目的一部分,我需要一个PHP网站才能读取和写入Microsoft Dynamics导航2016的Odata服务.
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导航2016使用 Odata v3标准.
Microsoft Dynamics NAV 2016 uses the Odata v3 standard.
现在,让我们以我的customer
服务为例.
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 :
https://<Server>:<WebServicePort>/<ServerInstance>/OData/Company(\'<CompanyName>\')/customer
获取单个实体
使用具有以下格式的链接,可以基于id
获取单个customer
实体,效果很好:
Fetching a single entity
Fetching a single customer
entity based on id
works fine, using a link with the following format :
https://<Server>:<WebServicePort>/<ServerInstance>/OData/Company(\'<CompanyName>\')/customer(\'<Id>\')
获取全局元数据
使用以下格式的链接来获得我所有服务的$metadata
概述很好(尽管它缺少Json支持):
Fetching the global metadata
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 :
https://<Server>:<WebServicePort>/<ServerInstance>/OData/$metadata
获取特定于集合的元数据
现在,基于两个 Odata v3规范和我的客户概览服务的odata.metadata
属性值,我希望能够使用链接获得customer
实体的$metadata
概览.具有以下格式:
Fetching collection-specific 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 :
https://<Server>:<WebServicePort>/<ServerInstance>/OData/$metadata#customer
这不符合预期.请参阅下面的The issue
小节.
This doesn't work as expected. See sub-section The issue
below.
同样,基于两个在检索单个客户时,Odata v3规范和数据集的odata.metadata
属性的值,我希望能够大致了解customer
实体,使用具有以下格式的链接:
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 :
https://<Server>:<WebServicePort>/<ServerInstance>/OData/$metadata#customer/@<FieldName>
这不符合预期.请参阅下面的The issue
小节.
This doesn't work as expected. See sub-section The issue
below.
由于某些原因,$metadata
之后的所有内容似乎都将被忽略.这意味着最后三个URL给我的输出完全相同,这不是我期望的.
For some reason, everything following $metadata
appears to be ignored. This means that the last three URLs give me the exact same output, which is not what I expected.
- 就像我在上文
The context
部分的Fetching collection-specific metadata
和Fetching entity-specific metadata
小节中尝试的那样,是否可以仅获取一个集合或实体的元数据? - 如果是,我在这里做错了什么?我想念什么?
- Is it possible to fetch the metadata of just one collection or entity, as I'm trying in sub-sections
Fetching collection-specific metadata
andFetching entity-specific metadata
of myThe context
section hereabove? - If yes, what I doing wrong here? What am I missing?
推荐答案
为 @xuzhg 在注释中建议,并由Github指出,例如> 支持元数据作为服务(#181) ,看来Odata $metadata
并不是真正的动态服务.相反,它只是一个XML文件.
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. Instead, it's just a single XML file.
这不仅解释了为什么在格式为https://<Server>:<WebServicePort>/<ServerInstance>/OData/$metadata#...
的链接中$ metadata之后的任何内容都被忽略,还解释了为什么它仅支持XML而不支持Json(与实际的Odata服务不同)的原因.
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).
这篇关于在Microsoft Dynamics导航2016中使用Odata Web服务为特定集合或实体获取$ metadata的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!