Sunday, January 13, 2013

CommunicationException in WCF Service

CommunicationException in WCF Service

My problem is that AddExcursionAsync doesn't work, it shows CommunicationException. In Console application this code works well. But in Silverlight it makes error. Functions AddListOgTourNumbersAsync and GetListOfTourNumberAsync work correctly. Where I did the error?

Code:

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

Answers & Comments...

Answer: 1

I have also battled with CommunicationException(s). At that point, I believe the network were experiencing regular problems.

In my scenario I had to stabilise this call with a retry algorithm.

I'm not saying you should do this all the time, but use it to test.

In this code, the exception is allowed to be thrown if the 3rd attempt fails.

    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;             }         }     } 
by : Martin Lotteringhttp://stackoverflow.com/users/1308645




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog