1

我做了以下并得到以下错误消息:

错误信息:

mscorlib.dll 中出现“System.AggregateException”类型的异常,但未在用户代码中处理附加信息:出现一个或多个错误。如果有这个异常的处理程序,程序可以安全地继续。

问题 :

a)上面代码中的问题似乎是什么,因为我只是想检索一条记录。

b) 必须在 WinRT 或 Windows 商店应用程序中使用异步方法?

c) 下面的代码能否从 Navision 检索记录?

-----1-------- Windows store App 访问 Nav Web Services

1.1 增加WinRT App中的服务引用
1.2 WinRT App中增加了class1.cs


私有异步无效 btnImportCustomer_Click(对象发送者,RoutedEventArgs e)
{
    任务_asyncCustomer = Class1.Customer.Listing.GetAsyncRecords("Y007");



    ### 在这里遇到错误:####

   字符串 g_strmsg = _asyncCustomer.Result.No + " " +_asyncCustomer.Result.Name;

}


--2------------ Class1.cs 在 WinRT 应用项目中使用:

使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;

命名空间 MobileNAVSalesSystem
{
    类 Class1
    {
        公共静态字符串 _webserviceurlpage = "http://{0}:{1}/{2}/WS/{3}/Page/{4}";
        公共静态字符串 _webserviceurlcodeunit = "http://{0}:{1}/{2}/WS/{3}/Codeunit/{4}";
        公共静态 Uri _webserviceuripage = null;
        公共静态 Uri _webserviceuricodeunit = null;


  #region 客户

        公共类客户
        {
            公共课卡
            {
                //为卡片类型做一些事情
            }

            公开课清单
            {
                公共静态 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");
                    返回_ws;
                }



   //--------------------------- 使用异步方法

     公共静态异步任务GetAsyncRecords(字符串_No)
     {
             wsCustomerList.Customer_List_PortClient _ws = GetService();
             wsCustomerList.Customer_List _List = (await _ws.ReadAsync(_No)).Customer_List;
             if (_ws.State == System.ServiceModel.CommunicationState.Opened)
                        等待 _ws.CloseAsync();
                    返回_列表;
      }

  公共静态异步任务 GetAsyncRecords(wsCustomerList.Customer_List_Filter[] _filters)
     {
            wsCustomerList.Customer_List_PortClient _ws = GetService();
             wsCustomerList.Customer_List[] _List;
             列表_filterArray = new List();
                    _filterArray.AddRange(_filters);
                    _List = (await _ws.ReadMultipleAsync(_filterArray.ToArray(), null, 0)).ReadMultiple_Result1;
             if (_ws.State == System.ServiceModel.CommunicationState.Opened)
                        等待 _ws.CloseAsync();
                       返回_列表;
                }

  公共静态异步任务 GetAsyncRecords(wsCustomerList.Customer_List_Filter[] _filters, string _bookmarkkey)
     {
        wsCustomerList.Customer_List_PortClient _ws = GetService();
        wsCustomerList.Customer_List[] _List;
                    列表_filterArray = new List();
        _filterArray.AddRange(_filters);
       _List = (等待 _ws.ReadMultipleAsync(_filterArray.ToArray(), _bookmarkkey, 0)).ReadMultiple_Result1;
        if (_ws.State == System.ServiceModel.CommunicationState.Opened)
                  等待 _ws.CloseAsync();
                返回_列表;
        }

  公共静态异步任务 GetAsyncRecords(wsCustomerList.Customer_List_Filter[] _filters, string _bookmarkkey, int _setsize)
    {
           wsCustomerList.Customer_List_PortClient _ws = GetService();
           wsCustomerList.Customer_List[] _List;
            列表_filterArray = new List();
                    _filterArray.AddRange(_filters);
           _List = (等待 _ws.ReadMultipleAsync(_filterArray.ToArray(), _bookmarkkey, _setsize)).ReadMultiple_Result1;
            if (_ws.State == System.ServiceModel.CommunicationState.Opened)
                        等待 _ws.CloseAsync();
                    返回_列表;
                }

            }
        }

        #endregion
    }
//--- 结束命名空间
}

4

1 回答 1

0

我知道这是不久前发布的这个问题,但其他人可能会偶然发现它,所以这里是:

a)上面代码中的问题似乎是什么,因为我只是想检索一条记录。

您的返回类型似乎不正确。

b) 必须在 WinRT 或 Windows 商店应用程序中使用异步方法?

是的,在使用 windows mobile 平台(windows store 应用程序和 windows phone 应用程序)时,您必须使用异步调用。

c) 下面的代码能否从 Navision 检索记录?

很难说,但在我看来,您尝试检索的数据格式不正确。我将从我当前的一个项目中给你一个简单的例子,我在其中检索登录名:

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        await call();
    }

    private async Task call()
    {
        BasicHttpBinding binding = new BasicHttpBinding();
        NetworkCredential cred = new NetworkCredential("username", "password", "domain");
        WS_PortClient ws = new WS_PortClient(binding, new EndpointAddress("Webservice-URL"));

        binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
        ws.ClientCredentials.Windows.ClientCredential = cred;

        CheckLogin_Result s = await ws.CheckLoginAsync("parameter");
        string k = s.return_value.ToString();
        MessageDialog d = new MessageDialog(k, "message");
        await d.ShowAsync();
    }

希望能帮助到你!

于 2014-09-22T08:43:10.117 回答