简体   繁体   English

在 Microsoft Dynamics NAV 2016 中使用 Odata Web 服务获取特定集合或实体的 $metadata

[英]Fetching $metadata for a specific collection or entity with Odata web services in Microsoft Dynamics NAV 2016

The environment环境

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 标准


The context上下文

Now, let's take my customer service as an example.现在,让我们以我的customer服务为例。

Fetching a collection of entities获取实体集合

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 entity获取单个实体

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>\')

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 :使用以下格式的链接获取我所有服务的$metadata概览可以正常工作(尽管它缺乏 Json 支持):

https://<Server>:<WebServicePort>/<ServerInstance>/OData/$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 :现在,基于 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小节。

Fetching entity-specific metadata获取实体特定的元数据

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小节。

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 给了我完全相同的输出,这不是我所期望的。


The actual question(s)实际问题

  • Is it possible to fetch the metadata of just one collection or entity, as I'm trying in sub-sections 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尝试的那样?
  • If yes, what I doing wrong here?如果是,我在这里做错了什么? What am I missing?我错过了什么?

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属性为somepropProperty元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM