0

私の問題は、AddExcursionAsync が機能しないことです。CommunicationException が表示されます。コンソール アプリケーションでは、このコードはうまく機能します。しかし、Silverlight ではエラーが発生します。関数 AddListOgTourNumbersAsync および GetListOfTourNumberAsync が正しく機能します。どこでエラーをしましたか?

コード:

private AdminServiceClient client;
    public AddExcursionDialog()
    {
        InitializeComponent();
        DurationElement.Value = new DateTime();
        client = new AdminServiceClient();
        client.GetListOfTourNumberCompleted += new EventHandler<GetListOfTourNumberCompletedEventArgs>(GetListOfTourNumber);
        client.AddListOgTourNumbersCompleted += new EventHandler<AsyncCompletedEventArgs>(AddListOfTourNumbers);
        client.AddExcursionCompleted += new EventHandler<AsyncCompletedEventArgs>(AddExcursion);
    }
    private void OKButton_Click(object sender, RoutedEventArgs e)
    {
        excursion = new Excursion();
        excursion.Name = NameText.Text;
        excursion.Cost = Convert.ToDouble(CostText.Text);
        excursion.Place = PlaceText.Text;
        excursion.Duration= (DateTime)DurationElement.Value;
        excursion.Agency_id = tour_names[AgencyCB.SelectedValue.ToString()];
        excursion.MaxPpl = Convert.ToInt32(MaxPplText.Text);
        client.GetListOfTourNumberAsync();
        client.AddExcursionAsync(excursion);
        client.AddListOgTourNumbersAsync(tour_id, excursion.NumberOfList);
        this.DialogResult = true;
    }
4

1 に答える 1

0

私もと戦いましたCommunicationException(s)。その時点で、ネットワークは定期的に問題を抱えていたと思います。

私のシナリオでは、再試行アルゴリズムを使用してこの呼び出しを安定させる必要がありました。

私はあなたがいつもこれをするべきだと言っているのではありませんが、それを使ってテストしてください。

このコードでは、3回目の試行が失敗した場合に例外をスローできます。

    string[] Images64;

    try { /* 1st try */
        Images64 = _VideoClient.GetImagesStr(ImagePaths[0], ImagePaths[1], LFrame, RFrame);
    }
    catch (CommunicationException) {

        try { /* 2nd try */
            Images64 = _VideoClient.GetImagesStr(ImagePaths[0], ImagePaths[1], LFrame, RFrame);
        }
        catch (CommunicationException) {

            try { /* 3rd try */
                Images64 = _VideoClient.GetImagesStr(ImagePaths[0], ImagePaths[1], LFrame, RFrame);
            }
            catch (CommunicationException) {

                throw;
            }
        }
    }
于 2013-01-12T13:15:35.837 に答える