1

私は次のことを行い、以下のエラーメッセージを受け取りました:

エラーメッセージ:

タイプ 'System.AggregateException' の例外が mscorlib.dll で発生しましたが、ユーザー コードで処理されませんでした 追加情報: 1 つ以上のエラーが発生しました。この例外のハンドラがあれば、プログラムは安全に続行できます。

質問 :

a)レコードを取得したかっただけなので、上記のコードの問題と思われるもの。

b) WinRT または Windows ストア アプリで非同期メソッドを使用する必要がありますか?

c) 以下のコードは Navision からレコードを取得できますか?

---1------- Nav Web サービスにアクセスするための Windows ストア アプリ

1.1 WinRT アプリにサービス参照を追加
1.2 WinRT アプリに class1.cs を追加


private async void btnImportCustomer_Click(オブジェクト送信者, RoutedEventArgs e)
{
    Task _asyncCustomer = Class1.Customer.Listing.GetAsyncRecords("Y007");



    ### ここでエラーが発生しました: ####

   文字列 g_strmsg = _asyncCustomer.Result.No + " “ +_asyncCustomer.Result.Name;

}


-----2------------- WinRT アプリ プロジェクト内での Class1.cs の使用:

システムを使用する;
System.Collections.Generic の使用;
System.Linq を使用します。
System.Text を使用します。
System.Threading.Tasks の使用;

名前空間 MobileNAVSalesSystem
{
    クラス 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 顧客

        public クラス 顧客
        {
            パブリック クラス カード
            {
                // カード タイプを処理する
            }

            public クラス リスト
            {
                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");
                    _ws を返します。
                }



   //-------------------------- 非同期メソッドの使用

     public static async Task 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();
                    _List を返します。
      }

  public static async Task GetAsyncRecords(wsCustomerList.Customer_List_Filter[] _filters)
     {
            wsCustomerList.Customer_List_PortClient _ws = GetService();
             wsCustomerList.Customer_List[] _List;
             List _filterArray = 新しい List();
                    _filterArray.AddRange(_filters);
                    _List = (await _ws.ReadMultipleAsync(_filterArray.ToArray(), null, 0)).ReadMultiple_Result1;
             if (_ws.State == System.ServiceModel.CommunicationState.Opened)
                        await _ws.CloseAsync();
                       _List を返します。
                }

  public static async Task GetAsyncRecords(wsCustomerList.Customer_List_Filter[] _filters, string _bookmarkkey)
     {
        wsCustomerList.Customer_List_PortClient _ws = GetService();
        wsCustomerList.Customer_List[] _List;
                    List _filterArray = 新しい List();
        _filterArray.AddRange(_filters);
       _List = (await _ws.ReadMultipleAsync(_filterArray.ToArray(), _bookmarkkey, 0)).ReadMultiple_Result1;
        if (_ws.State == System.ServiceModel.CommunicationState.Opened)
                  await _ws.CloseAsync();
                _List を返します。
        }

  public static async Task GetAsyncRecords(wsCustomerList.Customer_List_Filter[] _filters, string _bookmarkkey, int _setsize)
    {
           wsCustomerList.Customer_List_PortClient _ws = GetService();
           wsCustomerList.Customer_List[] _List;
            List _filterArray = 新しい List();
                    _filterArray.AddRange(_filters);
           _List = (await _ws.ReadMultipleAsync(_filterArray.ToArray(), _bookmarkkey, _setsize)).ReadMultiple_Result1;
            if (_ws.State == System.ServiceModel.CommunicationState.Opened)
                        await _ws.CloseAsync();
                    _List を返します。
                }

            }
        }

        #endregion
    }
//--- 名前空間の終了
}

4

1 に答える 1

0

この質問が投稿されたのは少し前であることは知っていますが、他の人がそれに出くわす可能性があるので、ここに行きます:

a)レコードを取得したかっただけなので、上記のコードの問題と思われるもの。

戻り値の型が間違っているようです。

b) WinRT または Windows ストア アプリで非同期メソッドを使用する必要がありますか?

はい、Windows モバイル プラットフォーム (Windows ストア アプリと Windows Phone アプリ) を使用する場合は、非同期呼び出しを使用する必要があります。

c) 以下のコードは Navision からレコードを取得できますか?

わかりにくいですが、取得しようとしているデータの形式が正しくないようです。ログインを取得する現在のプロジェクトの 1 つからの簡単な例を示します。

    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 に答える