我做了以下并得到以下错误消息:
错误信息:
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
}
//--- 结束命名空间
}