Quantcast
Channel: Microsoft Dynamics NAV Forum - Recent Threads
Viewing all articles
Browse latest Browse all 29197

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

$
0
0

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

}


Viewing all articles
Browse latest Browse all 29197

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>