Open Forum

Expand all | Collapse all

Amazon Integration using C# DLL (a bit technical)

  • 1.  Amazon Integration using C# DLL (a bit technical)

    TOP CONTRIBUTOR
    Posted Sep 15, 2017 04:42 PM
    There are a few different ways to pull orders from Amazon that work with NAV:C# DLL or HTTP Request using Amazon MarketPlace Web Services.

    I am getting stuck with both methods so if anyone has successfully done either of these please contact me (I know your out there).  My question is in regards to the C# DLL method.  I can do this in C# directly but as soon as I try transfer the same code into NAV I am getting a silly error.

    There is a bunch of parameters that you need to set when calling the ListOrdersRequest but the one that I am stuck on is the MarkPlaceID which is required.  The thing that makes this parameter a little weird is that it is expecting a List of strings not a text variable.  So as you can see below this parameter is expected to be a Dotnet List variable (System.Collections.Generic.List'1).


    So I write the code to handle this:
    MarketPlaceList := MarketPlaceList.List();
    MarketPlaceList.Add(MyMarketPlaceID);
    request.MarketplaceId := MarketPlaceList;

    Everything compiles as it should but I get a runtime error:

    This is just plain wrong since it does match.  Same code works fine in C# just not NAV.  Has anyone encountered this and if so what is your workaround?



    ------------------------------
    Jason Wilder
    Senior Application Developer
    Stonewall Kitchen
    York ME
    ------------------------------


  • 2.  RE: Amazon Integration using C# DLL (a bit technical)

    Posted Sep 18, 2017 10:21 AM
    Hi,  we are using HTTP Request to communicate with Amazon MarketPlace Web Services from NAV.  Since the request ends up being all text, we are not running into your issues with the .net list type.

    See this video for an example:

     [Demo] Microsoft Dynamics NAV and Amazon Integration: What's Possible Part 1
    YouTube remove preview
    [Demo] Microsoft Dynamics NAV and Amazon Integration: What's Possible Part 1
    Most retailers are including Amazon in their e-commerce strategies. But with fierce competition, you need to determine the best strategy for including this channel into your business processes and the best way to do it.
    View this on YouTube >


    ------------------------------
    Matt Street
    ArcherPoint Inc.
    South Bend IN
    ------------------------------



  • 3.  RE: Amazon Integration using C# DLL (a bit technical)

    Posted Sep 18, 2017 02:07 PM
    ​Hello,

    As a disclaimer I have never worked with MWS but here is my take on your issue:
    When creating your List object in NAV you do not specify the type of List (List<string> or List<int>) and that means it will create a List<object>.

    I am guessing the MarketPlaceId properties of the request is strongly-typed and will expect a List<string>.

    My recommendation would be to create a custom add-in that will encapsulate all your interactions with your web service. Then from NAV your call your custom DLL only with simple explicit types like string[] or int[] or decimal.

    ------------------------------
    Tijane Ndiongue
    Forum Energy Technologies
    Houston TX
    ------------------------------



  • 4.  RE: Amazon Integration using C# DLL (a bit technical)

    TOP CONTRIBUTOR
    Posted Sep 19, 2017 09:06 AM
    Thanks for the feedback!  Matt that video doesn't show me the code and Tijane that will be a last resort for me.

    I have gotten a little further with this.  I think the List Dotnet object is being instantiated as List<Object> and not list List<String>.  Here is an article that says you can't do this with C/AL but then goes on to give an example of how to do this (mylist := x.GetAStringList(); ).  I really do not get this example as the details are just not there.  Here is the article by Microsoft:
    https://msdn.microsoft.com/en-us/library/hh169195(v=nav.90).aspx

    Can someone help me figure out how to instantiate MyList as MyList<String> in C/AL?

    ------------------------------
    Jason Wilder
    Senior Application Developer
    Stonewall Kitchen
    York ME
    ------------------------------



  • 5.  RE: Amazon Integration using C# DLL (a bit technical)

    Posted Sep 19, 2017 10:07 AM
    ​​Hello Jason,

    This article confirm what I was referring to. If you create the list in NAV it will be weakly-typed. However they used another object (x) for which the method GetAStringList returns a strongly-typed List<string> to instantiate a  List<string> in NAV.

    So I don't think in NAV you can specify the type when using the List constructor you will have to use another object that will instantiate it for you.

    You can create an interop class in Visual Studio with static methods that returns an empty List<string> then call that class to instantiate your object in NAV. It the same as the example for the Array found here https://msdn.microsoft.com/en-us/library/hh167470(v=nav.90).aspx.

    ------------------------------
    Tijane Ndiongue
    Forum Energy Technologies
    Houston TX
    ------------------------------



  • 6.  RE: Amazon Integration using C# DLL (a bit technical)

    TOP CONTRIBUTOR
    Posted Sep 22, 2017 07:12 AM
    Tijane I was about to implement your solution when a colleague (Jack Reynolds, thanks!) pointed me towards a post that answers this issue all within NAV.  Here is the article:  http://vjeko.com/generics-in-net-interop-for-nav-2013/.
    So I have a function in NAV now called InstantiateStringList that creates a List as a string and solves the error I was running into.  Here it is:
    Local Variables:
    ObjectList DotNet System.Collections.Generic.List`1.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    Type DotNet System.Type.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    Array DotNet System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    String DotNet System.String.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    Activator DotNet System.Activator.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    Global Variables:
    StringList DotNet System.Collections.Generic.List`1.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    New Function:
    // Code below needed to instantiate the list as a System.String instead of System.Object
    CLEAR(StringList);
    "Array" := "Array".CreateInstance(GETDOTNETTYPE(Type),1);
    "Array".SetValue(GETDOTNETTYPE(String),0);
    Type := GETDOTNETTYPE(StringList);
    Type := Type.MakeGenericType("Array");
    StringList := Activator.CreateInstance(Type);

    If you come across this post and you are working on Amazon integration please feel free to message me and I will help you out.







    ------------------------------
    Jason Wilder
    Senior Application Developer
    Stonewall Kitchen
    York ME
    ------------------------------



  • 7.  RE: Amazon Integration using C# DLL (a bit technical)

    Posted Sep 25, 2017 09:25 AM
    ​Hello Jason,

    I am glad you solved your issue. It is a really interesting solution. Thank you for sharing.

    ------------------------------
    Tijane Ndiongue
    Forum Energy Technologies
    Houston TX
    ------------------------------