Request using Dynamic365 api

Posted by goo on 07-Nov-2017 09:44

11.7

Where can I find some documentation of how to use the OpenEdge.Net stuff?

I am trying to communicate With Dynamics365 using OpenEdge HTTP stuff.

I have received a token, and Wonder

    oAuthParam = AuthenticationParameters:CreateFromResourceUrlAsync(oUri).
    PAUSE 0.3 NO-MESSAGE.
    oAuthContext = NEW AuthenticationContext(oAuthParam:Result:Authority).
    PAUSE 0.3 NO-MESSAGE.
    oClientCred = NEW Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential(username,password).
    PAUSE 0.3 NO-MESSAGE.
    Token = oAuthContext:AcquireToken(oAuthParam:Result:Resource,clientId,oClientCred):AccessToken.

So far, ok.

Then I want to send a request for some member  information:

 METHOD PUBLIC VOID getMedlem(input ipMedlemNr as int ):
    def var ContactQuery as char no-undo.
    ContactQuery = "contacts?$select=contactid&$filter=acan_medlemsnummer eq '~{" + string(ipMedlemNr) + "~}'&$top=1".
   
    oClient  = ClientBuilder:Build():Client.
    oURI:PathAndQuery = ContactQuery.
    oRequest = RequestBuilder:Get(oURI).
/*                :AcceptJson()*/
/*                :Request.    */

    oRequest:CharacterEncoding = 'UTF-8'.
  
    oResponse = oClient:Execute(oRequest).

It will not compile, and If I remove the comments for :AcceptJson and :Req.. it also gives me errors on those..

I am trying to implement from this examplecode in C#:

/*            var wc = new WebClient();                                        */
/*            wc.Encoding = Encoding.UTF8;                                     */
/*                                                                             */
/*            wc.BaseAddress = webApiBaseUrl;                                  */
/*                                                                             */
/*            wc.Headers.Add("OData-MaxVersion", "4.0");                       */
/*            wc.Headers.Add("OData-Version", "4.0");                          */
/*            wc.Headers.Add("Accept", "application/json");                    */
/*            wc.Headers.Add("Content-Type", "application/json;charset=utf-8");*/
/*            wc.Headers.Add("Authorization", "Bearer " + accessToken);        */
/*                                                                             */
/*            return wc;                                                       */

1. What is wrong With the code?

Posted by tbergman on 07-Nov-2017 12:15

Since you're already in a Microsoft world due to your use of the Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential, why not just use the Microsoft .Net WebClient?

The translation from C# is usually very easy.

Tom

All Replies

Posted by Brian K. Maher on 07-Nov-2017 10:30
Posted by Peter Judge on 07-Nov-2017 12:03

THere's no property on the URI called PathAndQuery. YOu have to add the path and query separately.  YOu can also pass a string of the whole URL into the RequestBuilder's Get() method.

Posted by tbergman on 07-Nov-2017 12:15

Since you're already in a Microsoft world due to your use of the Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential, why not just use the Microsoft .Net WebClient?

The translation from C# is usually very easy.

Tom

Posted by Roger Blanchard on 08-Nov-2017 06:42

I agree with Tom...C# to ABL is pretty straight forward. Tom also did a presentation with some great samples.

Posted by marian.edu on 08-Nov-2017 06:54

If you experience connection problems check if the other party is enforcing TLS (not supporting SSL), OE sockets supports that since 11.6 if you go the plain 4GL route and for .NET you need at least 4.5 (not available in 4.0 shipped with OE)… in 4.6 TLS is the default, in 4.5 you must set that as a default:


ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12


Marian Edu

Acorn IT 
+40 740 036 212

Posted by Roger Blanchard on 08-Nov-2017 06:57

Marian is correct. For .NET you need 4.5 but as long as 4.5 is installed on the machine you are good since 4.5 replaces some of the core 4.0 libraries.

Posted by Roger Blanchard on 08-Nov-2017 06:57

I believe 11.7 actually uses .net 4.6

Posted by Roger Blanchard on 08-Nov-2017 07:00

For a list of .net framework versions supported by OE you can look at this article;

knowledgebase.progress.com/.../000054406

Posted by goo on 08-Nov-2017 07:10

Thanks, I went for .Net solution, and that worked. I am still a bit confused using the OpenEdge part, but hi, learning is cool.

This thread is closed