The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

how to handle WCF timeout exception RRS feed

  • General discussion

  • How can I capture a wcf exception like time out. For example in the code below it times out before 'Completed' gets results.

    public void PerformGetEnableCheckIn()
    SeeYaThereWCFClient wcf = new SeeYaThereWCFClient();
    wcf.GetEnableCheckInCompleted += wcf_GetEnableCheckInCompleted;
    wcf.GetEnableCheckInAsync(UserId, DateTime.Now);

    private void wcf_GetEnableCheckInCompleted(Object sender, GetEnableCheckInCompletedEventArgs e)
    bool res = e.Result;
    if (res != null)
    // do something

    Sunday, January 16, 2011 5:42 AM

All replies

  • Hi There try this instead private void wcf_GetEnableCheckInCompleted(Object sender, GetEnableCheckInCompletedEventArgs e) { if (e.Error != null) { //Alert the user that somethign has gone wrong return; } //Now interogate the e.Result value (if applicable) and act on it } You need to check the e.Error property, not the e.Result value. if e.Error is ! null then something has gone wrong. e.Result will store any result data you are passing back only. NOTE: When you are debugging, the IDE will always halt in the generated callback code to show you where the fault has occured (timeout/bad method/params etc....) but execution will then continue to the callback method where e.Error will not equal null ths your error handling code will kick in. This behaviour will ofcourse not happen on the device OR if you then run your app on the emulator without debugging. Hope this helps. Jason
    Monday, January 17, 2011 2:53 AM
  • Thanks for the reply.

    I agree I should be checking for e.Error in the Completed procedure. But the error happens before the Completed procudure. It actually throws in the WCF client class.

    I haven't seen any code samples that show how to handle the WCF timeout issue. Was hoping someone here could provide an example.
    Friday, January 28, 2011 2:48 AM
  • Sunday, May 29, 2011 6:46 PM