C# Store app connection to Navision through service not working properly


  • Hi, 

    I made a C# Store app application which talks with a navision backend through a service. The main problem is: When i make a navision call, the await for the async method does not await. It just runs and 'restarts' the page. For this instance i get double data on my screen, or when i use the boolean as shown below. I will get the proper amount of items, but it will not bind to my screen. 

    Edit: the ObservableCollection and dataViewModel also knows that i have items in them, binding in XAML is not an issue.

    Now i want to call the service not ASYNC. so it has to wait for it in order to work. Also when i want to configure the service Reference the area where i can set the option to "Allow generation of asynchronous operations" is greyed out. 

    Can't place picture do to verify troubles.

    So: how can i adjust my app so i can make use of the service without using the Await statement OR how can i make the method not to quit on the await and restart the page so i get double data?

    Hope you can help me, thanks in advance.

     // PVU
            private bool IsRunning;
            // END PVU
            public async Task getNAVCategorie()
                if (IsRunning)
                    IsRunning = true;
                    Groups = new ObservableCollection<ProductGroup>();
                    BasicHttpBinding binding = new BasicHttpBinding { };
                    binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                    EndpointAddress epa = new EndpointAddress("this is an adress");
                    AppService_PortClient ws = new AppService_PortClient(binding, epa);
                    ws.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
                    ws.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Delegation;
                    ItemCategory ic = new ItemCategory();
                    GetItemCategory catrequest = new GetItemCategory(ic);
                    GetItemCategory_Result catresult = await ws.GetItemCategoryAsync(catrequest);
                    var results = catresult.itemCategoryExport.ItemCategorys;
                    foreach (ItemCategorys itemc in results)
                        ProductGroup p = new ProductGroup(itemc.Code, itemc.Description, "/Assets/logo.jpg");
                    IsRunning = false;

    • Edited by Proliges Thursday, May 15, 2014 2:20 PM extra information added
    Thursday, May 15, 2014 2:19 PM

All replies

  • I think this will work:

    GetItemCategory_Result catresult = ws.GetItemCategoryAsync(catrequest).GetResults();

    If not, then you can also try this:

    WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.UseCorporateNetwork, new Uri("https://microsoft.com")).Completed((GetItemCategory catresult ) => {var results = catresult.itemCategoryExport.ItemCategorys; foreach (ItemCategorys itemc in results) { ProductGroup p = new ProductGroup(itemc.Code, itemc.Description, "/Assets/logo.jpg"); Groups.Add(p); });

    Note that I haven't tested this.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, May 16, 2014 12:16 PM
  • GetItemCategory_Result catresult = ws.GetItemCategoryAsync(catrequest).GetResults(); 

    Does not work because it does not contain a definition for "GetResult". 

    in the code block you posted there is an error in  WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.UseCorporateNetwork, new Uri("https://microsoft.com")).Completed((GetItemCategory catresult ) =>

    because it does not accept only 1 argument. At this point I lack the skills to resolve this problem since its my first time working with NAV connections.

    Monday, May 19, 2014 10:14 AM