Working with the OData Endpoint in Dynamics 365 for Operations

 

The OData endpoint is a new REST-based service that allows for integrating with Dynamics 365 for Operations. Below are some tips to help with using an OData client to authenticate and use methods to read and write data in the system.

Data Entities

Data Entities that are marked ‘Yes’ for the ‘Is Public’ property will be available as an OData endpoint. You can consume this OData endpoint in your external application such as a .Net application for integration scenarios.

In the screenshot below, I have created a custom data entity called CPRCustCreditRatingEntity. Note the Is PublicPublic Collection Name and Public Entity Name properties:

odata-endpoint_chris

When viewed using the Chrome browser, I can see my custom Data entity is available:

odata-endpoint_chris-2

od-endpoint_chris-3

Tip: If using IE to view the OData endpoint, you might have to open the JSON results in a separate file download. Chrome will automatically show the JSON results in the browser.

Creating a OData Client Application

Use the OData v4 Client Code Generator in your Visual Studio application to build the OData entity proxy classes. This can be downloaded and installed from with Visual Studio. Once it is installed, you can add the OData client to the application. In the following screenshots, I downloaded it and then added it to my C# Console application project:

od-endpoint_chris-4

od-endpoint_chris-5

This will create a file with an extension of tt which stands for Text Template. Update the MetadataDocumentUri string value in the tt file so it contains your OData metadata endpoint. For example, mine is:

public const string MetadataDocumentUri = “https://usnconeboxax1aos.cloud.onebox.dynamics.com/data/$metadata”;

Lastly, right click on the tt file and choose to ‘Run custom tool’. This will read the metadata and build a large class file (45+ MB). It may take several minutes to complete. You can explore the CS file when it completes.

od-endpoint_6

Using the generated proxy classes

The generated proxy classes let you instantiate the data entity objects, set properties, and call methods to interact with the OData endpoint. The following is an example of reading a CustCreditRating record using a LINQ (System.Linq) query pattern:

 
 
 
 
 
 
C#

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

//Get Single CustCreditRating
Console.WriteLine("Get a single CustCreditRating instance...");
CustCreditRating existCustCreditRating = GetCustCreditRating("USMF", "US-010");
Console.WriteLine("Credit Rating for {0} is {1}. Press Enter.", existCustCreditRating.CustomerAccount, existCustCreditRating.CreditRating);
Console.ReadLine();
 
The GetCustCreditRating method:
#region Get Single CustCreditRating
        private static CustCreditRating GetCustCreditRating(string targetAXLegalEntity, string customerAccount)
        {
            context.SendingRequest2 += new EventHandler<SendingRequest2EventArgs>(delegate (object sender, SendingRequest2EventArgs e)
            {
                var authenticationHeader = OAuthHelper.GetAuthenticationHeader();
                e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader);
            });
 
            var custCreditRatingQuery = from entity in context.CustCreditRatings
                                        where entity.DataAreaId == targetAXLegalEntity
                              && entity.CustomerAccount == customerAccount
                              select entity;
 
            return (custCreditRatingQuery.Count() > 0) ? custCreditRatingQuery.First() : null;
        }
#endregion
 
The following code is a complete example of creating multiple Customer records using the OData endpoint:
using System;
using AuthenticationUtility;
using Microsoft.OData.Client;
using CustomerOdataClient.Microsoft.Dynamics.DataEntities;
 
namespace CustomerOdataClient
{
    class Program
    {
        private static string ODataEntityPath = ClientConfiguration.Default.ODataEndpointUri;
        private static Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute);
        private static Resources context = new Resources(oDataUri);
 
 
        static void Main(string[] args)
        {
            Console.WriteLine("Set HTTP header...");
            context.SendingRequest2 += new EventHandler<SendingRequest2EventArgs>(delegate (object sender, SendingRequest2EventArgs e)
            {
                var authenticationHeader = OAuthHelper.GetAuthenticationHeader();
                e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader);
            });
 
            Console.WriteLine("Creating new customer using Data Entity OData...");
            Customer myCustomer = new Customer();
            DataServiceCollection<Customer> customersCollection = new DataServiceCollection<Customer>(context);
 
            customersCollection.Add(myCustomer);
            
            myCustomer.CustomerAccount = "US-X11111";
            myCustomer.Name = "ABC Trees  111";
            myCustomer.CustomerGroupId = "10";
            myCustomer.SalesCurrencyCode = "USD";
            myCustomer.CreditRating = "Excellent";
            myCustomer.AddressCountryRegionId = "USA";
 
            #region Create multiple customers
            
            Customer myCustomer2 = new Customer();
            
            customersCollection.Add(myCustomer2);
 
            myCustomer2.CustomerAccount = "US-X22222";
            myCustomer2.Name = "ABC Rains vb";
            myCustomer2.CustomerGroupId = "10";
            //myCustomer2.SalesCurrencyCode = "USD";
            myCustomer2.CreditRating = "Excellent";
            myCustomer2.AddressCountryRegionId = "USA";
            
            #endregion
 
            DataServiceResponse response = null;
            try
            {
                response = context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset);
                Console.WriteLine("created ok");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.InnerException);
            }
            Console.ReadLine();
        }
    }
}

In the code above, two Customer objects are being created and passed into a DataServiceCollection named customersCollection. I am using the optional SaveChangesOptions.BatchWithSingleChangeset enum in the SaveChanges method. This means if one of the Customer objects fails validation then neither of the Customer objects are created. Since both Customers run under one batch in the HTTP call to the OData endpoint if one fails then they both do.

Lastly, the Resources object that has been instantiated as ‘context’, is using objects from the AuthenticationUtility project to help with authentication. This is a C# library project made of two classes to help in setting up the authentication to the OData endpoint and retrieving the authorization token. This AuthenticationUtility project can be found in Microsoft’s Dynamics AX Github repository at https://github.com/Microsoft/Dynamics-AX-Integration/tree/master/ServiceSamples/AuthenticationUtility.

Hopefully, this post can steer you in the right direction on how to successfully interact with the OData entities in Microsoft Dynamics 365 for Operations.

推荐这些文章:

docker端口映射或启动容器时报错Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen

现象:
[root@localhost ~]# docker run -d -p 9000:80 centos:httpd /bin/sh -c /usr/local/bin/start.shd5b2bd5a7bc4895a973fe61efd051847047d26385f65c278aaa09e4fa31c4d76docker: Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen (6bda693d1143657e46bee0300276a...

[WCF]:Could not find a base address that matches scheme net.pipe for the endpoint with binding NetNamedPipeBinding

问题
我的web.config中wcf的配置如下:
 
 <system.serviceModel>    <behaviors>      <serviceBehaviors>        <behavior name="WCFHostDemo.Contracts.Lib.HelloWorldServiceBehavior">  &...

tomcat系统架构

TOMCAT 7新特性   1 使用随机数去防止跨站脚本攻击。   2 改变了安全认证中的jessionid的机制,防止session攻击。   3 内存泄露的侦测和防止   4 在war文件外使用别名去存储静态内容。   TOMCAT 7的增强功能   5 对Servlet 3.0,JSP 2.2和JSP-EL 2。2的支持   6 更容易将Tomcat内嵌到应用去中去,比如JBoss   7 异步日志记录 
 
一、架构
下面谈谈我对Tomcat架构的理解
 
总体架构:
1、面...

WCF —— Endpoint & Binding & netTcpBinding Overview(转发)

相关资料
[原创]我的WCF之旅(1):创建一个简单的WCF程序[原创]我的WCF之旅(2):Endpoint Overview[原创]我的WCF之旅(3):在WCF中实现双向通信(Bi-directional Communication)[原创]我的WCF之旅(4):WCF中的序列化(Serialization)- Part I[原创]我的WCF之旅(4):WCF中的序列化(Serialization)- Part II[原创]我的WCF之旅(5):Service Contract中的重载(Overloading)[原创]我的WCF之旅(6):在Winform Application中调用...

go传参语糖发...string 实参可以不用传值

 
 
 
 

func (c *junoClient) OrderDeal(ctx context.Context, in *LibraAuditOrder, opts ...grpc.CallOption) (*RecordSet, error) {

 
out := new(RecordSet)

 
err := c.cc.Invoke(ctx, "/proto.Juno/OrderDeal", in, out, opts...)

 
if err != nil {

 
return...

samba getpeername failed. Error was Transport endpoint is not connected错误

问题描述:           在检查/var/log/messages日志文件时发现如下错误:                    smbd[15295]: getpeername failed. Error was Transport endpoint is not connected 解决方法:            在/...

linq to entity 插入一条记录后,怎么获取插入 这条记录的id

问题
表结构
ID 自动增长
CustomerName 用户姓名
linq to Entity 新增代码
Customer customer = new Customer(); customer.CustomerName = txtReceiver.Text;edm.AddToCustomer(customer);edm.SaveChanges();
问题:怎么才能在新增完之后 得到自动增长的ID的值 
补充:是如何才能得到ID   
           int intID=cu...

在k8s上使用clickhouse报Error sending request to endpoint错误的记录

 
 先放着,等找到问题解决方法后再补充
1、修改config.xml文件不成功
2、修改users.xml文件不成功
 MDZZ,K8s在部署项目后还使用了SkyWalking
这个导致了clickhouse出现了endpoint的问题

...

rasa培训课程:Rasa 3.X 项目实战之保险行业Insurance Bot智能业务对话机器人

课程标题:Rasa 3.X 项目实战之保险行业Insurance Bot智能业务对话机器人
 
课程关键字:Rasa Application、Insurance Bot、Debugging、Customer Service、Interactive Learning、Testing、Microservices、CollectingDispatcher、Tracker、Domain、Payload、Slot、Mapping、NLU、Policies、Dialogue Management、Graph Architecture、Rasa Architecture、Life Cycle、S...

docker: Error response from daemon: driver failed programming external connectivity on endpoint rabbitmq

 
 docker: Error response from daemon: driver failed programming external connectivity on endpoint rabbitmq (0c4296b4c0abde4a57cb6ba0987fa08d55ff190d83e54f53e91d63f1bbf32a00):  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 15692 -j DNAT --to-destination 17...

文章标题:Working with the OData Endpoint in Dynamics 365 for Operations
文章链接:https://www.dianjilingqu.com/51539.html
本文章来源于网络,版权归原作者所有,如果本站文章侵犯了您的权益,请联系我们删除,联系邮箱:saisai#email.cn,感谢支持理解。
THE END
< <上一篇
下一篇>>