【问题标题】:CommunicationException in WCF ServiceWCF 服务中的通信异常
【发布时间】:2013-01-11 08:43:23
【问题描述】:

我的问题是 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;
    }

【问题讨论】:

  • 必须在 Wcf 服务中添加服务契约

标签: wcf silverlight silverlight-4.0 silverlight-5.0


【解决方案1】:

我也和CommunicationException(s)打过仗。那时,我相信网络经常遇到问题。

在我的场景中,我必须使用 retry 算法来稳定这个调用。

我并不是说你应该一直这样做,而是用它来测试。

在这段代码中,如果第三次尝试失败,则允许抛出异常。

    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;
            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-07
    • 1970-01-01
    • 2011-10-17
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    相关资源
    最近更新 更多