Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

What is this msg when accessing NAV web service with Windows 8 app

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I did the following and got the below error msg:

The error message :

An exception of type 'System.AggregateException' occurred in mscorlib.dll but was not handled in user code

Additional information: One or more errors occurred.

If there is a handler for this exception, the program may be safely continued.

Question :

a)  What seems to be the problems in above code as I just wanted to retrieve a record.

b) Must use Async Methods in WinRT or Windows store app?

c) Will below code able to retrieve record from Navision?

-----1-------  Windows store App to access Nav Web Services

1.1 Added the service reference  in WinRT App

1.2 Added a class1.cs in WinRT App

private async void btnImportCustomer_Click(object sender, RoutedEventArgs e)

{

   Task<wsCustomerList.Customer_List> _asyncCustomer = Class1.Customer.Listing.GetAsyncRecords("Y007");

   ###  encounterd error here: ####

  string  g_strmsg = _asyncCustomer.Result.No + " “ +_asyncCustomer.Result.Name;

}

-----2----------     Class1.cs use inside WinRT App Project:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace MobileNAVSalesSystem

{

   class Class1

   {

       public static string _webserviceurlpage = "http ://{0}:{1}/{2}/WS/{3}/Page/{4}";

       public static string _webserviceurlcodeunit = "http://{0}:{1}/{2}/WS/{3}/Codeunit/{4}";

       public static Uri _webserviceuripage = null;

       public static Uri _webserviceuricodeunit = null;

 #region Customer

       public class Customer

       {

           public class Card

           {

               //Do something for Card Type

           }

           public class Listing

           {

               public static wsCustomerList.Customer_List_PortClient GetService()

               {

                   _webserviceuripage = new Uri(string.Format(_webserviceurlpage, "msxxx", "7047", "DynamicsNAV_xxx", Uri.EscapeDataString("Global xxx  Pte. Ltd."), "Customer List"));

                   System.ServiceModel.BasicHttpBinding _wSBinding = new System.ServiceModel.BasicHttpBinding();

                   _wSBinding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly;

                   _wSBinding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows;

                   _wSBinding.MaxBufferSize = Int32.MaxValue;

                   _wSBinding.MaxReceivedMessageSize = Int32.MaxValue;

                   //_wSBinding.UseDefaultWebProxy = false;

                   wsCustomerList.Customer_List_PortClient _ws = new wsCustomerList.Customer_List_PortClient(_wSBinding, new System.ServiceModel.EndpointAddress(_webserviceuripage));

                   _ws.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;

                   _ws.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("xxx","xxxx", "companyName");

                   return _ws;

               }

  //-------------------------- Using Async Methods

    public static async Task<wsCustomerList.Customer_List> GetAsyncRecords(string _No)

    {

            wsCustomerList.Customer_List_PortClient _ws = GetService();

            wsCustomerList.Customer_List _List = (await _ws.ReadAsync(_No)).Customer_List;

            if (_ws.State == System.ServiceModel.CommunicationState.Opened)

                       await _ws.CloseAsync();

                   return _List;

     }

 public static async Task<wsCustomerList.Customer_List[]> GetAsyncRecords(wsCustomerList.Customer_List_Filter[] _filters)

    {

           wsCustomerList.Customer_List_PortClient _ws = GetService();

            wsCustomerList.Customer_List[] _List;

            List<wsCustomerList.Customer_List_Filter> _filterArray = new List<wsCustomerList.Customer_List_Filter>();

                   _filterArray.AddRange(_filters);

                   _List = (await _ws.ReadMultipleAsync(_filterArray.ToArray(), null, 0)).ReadMultiple_Result1;

            if (_ws.State == System.ServiceModel.CommunicationState.Opened)

                       await _ws.CloseAsync();

                      return _List;

               }

 public static async Task<wsCustomerList.Customer_List[]> GetAsyncRecords(wsCustomerList.Customer_List_Filter[] _filters, string _bookmarkkey)

    {

       wsCustomerList.Customer_List_PortClient _ws = GetService();

       wsCustomerList.Customer_List[] _List;

                   List<wsCustomerList.Customer_List_Filter> _filterArray = new List<wsCustomerList.Customer_List_Filter>();

       _filterArray.AddRange(_filters);

      _List = (await _ws.ReadMultipleAsync(_filterArray.ToArray(), _bookmarkkey, 0)).ReadMultiple_Result1;

       if (_ws.State == System.ServiceModel.CommunicationState.Opened)

                 await _ws.CloseAsync();

               return _List;

       }

 public static async Task<wsCustomerList.Customer_List[]> GetAsyncRecords(wsCustomerList.Customer_List_Filter[] _filters, string _bookmarkkey, int _setsize)

   {

          wsCustomerList.Customer_List_PortClient _ws = GetService();

          wsCustomerList.Customer_List[] _List;

           List<wsCustomerList.Customer_List_Filter> _filterArray = new List<wsCustomerList.Customer_List_Filter>();

                   _filterArray.AddRange(_filters);

          _List = (await _ws.ReadMultipleAsync(_filterArray.ToArray(), _bookmarkkey, _setsize)).ReadMultiple_Result1;

           if (_ws.State == System.ServiceModel.CommunicationState.Opened)

                       await _ws.CloseAsync();

                   return _List;

               }

           }

       }

       #endregion

   }

//--- end namespace

}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: What is this msg when accessing NAV web service with Windows 8 app

    I used try -catch statement. It shows this error msg  as below:

    one or more errors

    I want to know will my Code work and is the way I handle the returned result correctly?

  • Suggested answer
    Aleksandar Totovic Profile Picture
    Aleksandar Totovic 16,765 on at
    RE: What is this msg when accessing NAV web service with Windows 8 app

    Maybe you can find a help on:

    msdn.microsoft.com/.../system.aggregateexception.aspx

    stackoverflow.com/.../how-to-fix-system-aggregateexception-occurred-in-mscorlib-dll

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans