首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WCF服务中的CommunicationException

WCF服务中的CommunicationException
EN

Stack Overflow用户
提问于 2013-01-11 16:43:23
回答 1查看 91关注 0票数 0

我的问题是AddExcursionAsync不工作,它显示的是CommunicationException。在控制台应用程序中,此代码运行良好。但在Silverlight中,它会出错。函数AddListOgTourNumbersAsync和GetListOfTourNumberAsync工作正常。我在哪里做错了?

代码:

代码语言:javascript
复制
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;
    }
EN

回答 1

Stack Overflow用户

发布于 2013-01-12 21:15:36

我也曾与CommunicationException(s)斗争过。在这一点上,我相信网络正在经历常规的问题。

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

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

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

代码语言:javascript
复制
    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;
            }
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14274451

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档