最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

来自OData服务的XML响应 / XML response from OData services

网络文摘 William 1772浏览 0评论
If you call OData services in AX 7 (Dynamics 365 for Finance and Operations), you typically get data in JSON format, like this:
{
  "@odata.context":"https://myaxinstance.cloudax.dynamics.com/data/$metadata","value":[
    {
      "name":"ElectronicPaymentTypes","kind":"EntitySet","url":"ElectronicPaymentTypes"
    },{
      "name":"ExpensePaymentDetails","kind":"EntitySet","url":"ExpensePaymentDetails"
    }
    ...
  ]
}
JSON is a simple, lightweight format with good support in many tools, but sometimes you would rather get XML. XML is by no mean deprecated – it’s more than a format; you get a whole platform with capabilities useful for validations (XML schema), querying (XPath, XQuery), transformations (XSLT) and so on. Or you simply have a component that accepts only XML and not JSON. Fortunately OData services aren’t limited to JSON; they can return XML as well. Simply add HTTP header Accept with value application/atom+xml,application/atomsvc+xml,application/xml and you’ll start getting the same data in XML format:
<ODataServiceDocument xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/Microsoft.OData.Core">
  <EntitySets>
    <ODataEntitySetInfo>
      <Name>ElectronicPaymentTypes</Name>
      <Title i:nil="true" />
      <Url>ElectronicPaymentTypes</Url>
    </ODataEntitySetInfo>
    <ODataEntitySetInfo>
      <Name>ExpensePaymentDetails</Name>
      <Title i:nil="true" />
      <Url>ExpensePaymentDetails</Url>
    </ODataEntitySetInfo><ODataEntitySetInfo>
  ...
  </EntitySets>
</ODataServiceDocument>
If you use Postman, for example, this is where you can put the header: Of course, that you get XML format doesn’t mean that you get the structure you want. You still may need to transform it to something more suitable for your purposes.
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址