Integration Doc - Beta testers needed

Let us remember that @Bart_Elia is doing this on his free time and he is a super busy guy, so let’s give him some room to breathe!
With that said, attached is a class I generated from the customer meta data

CustomerCls.cs (66.6 KB)

Basically it is an object representation of the JSONObject returned by the REST API. With this class in your project you can now serizlize the JSON into it and use it like you would the CustomerDataSet in the WCF Example.
Simply replace the QueryCustomer() method with the one below once you’ve imported the class into your project.

private static void QueryCustomer()
        {
            //Stand up which service to call
            HttpRequestMessage request = new HttpRequestMessage(
                HttpMethod.Post,
                ServiceUrl + "/Erp.Bo.CustomerSvc/GetByID");

            //Add the json payload
            request.Content =
                new StringContent(
                    JsonConvert.SerializeObject(
                        new
                        {
                            custNum = 2
                        }),
                    Encoding.Default,
                    "application/json");

            try
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                //Make the call
                var response = httpClient.SendAsync(request).Result;

                stopwatch.Stop();
                //var jsonResponse = GetObject(response);

                //Deserialize JSON Response into our JSONCustomer object
                JSONCustomer custDS= Newtonsoft.Json.JsonConvert.DeserializeObject<JSONCustomer>(response.Content.ReadAsStringAsync().Result);
                //Display the Customer's Name
                Console.WriteLine(custDS.returnObj.Customer[0].Name);

                //Console.WriteLine("Success:{0}", response.StatusCode == HttpStatusCode.Created);
                //Console.WriteLine("Response:{0}", jsonResponse.ToString());
                Console.WriteLine("Duration:{0}", stopwatch.Elapsed.TotalMilliseconds);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.ReadLine();
        }

You can generate the class a couple of ways, there are libraries out there that understand OData and will allow you to generate classes from the meta data directly, there are web utilities that will do it too (https://jsonutils.com/). The easiet way to do it is to paste the mata data into a visual studio class using the Paste Special functionality

6 Likes