You must Sign In to post a response.
  • Category: WCF

    Throwing an exception from callback in WCF Async

    I am using WCF Async calls in my project and i am using Client side asynchronous methods. I have a scenario like below -

    //Code in Business Layer and this method is called from Web layer
    private void GetGeneralNews()
    {
    client.BeginGetGeneralNewsFeed(GeneralNewsCallback, null);
    }

    private static void GeneralNewsCallback(IAsyncResult asyncResult)
    {
    string response = string.Empty;

    try
    {
    response = client.EndGetGeneralNewsFeed(asyncResult);
    }
    catch(Exception ex)
    {
    throw ex; // Here is the problem. It does not throw the exception to the web layer instead it will suppress the error.
    }
    }

    So as shown in the above code snippet it does not throw the exception from business layer to web layer as it will be suppressed here in business layer itself.

    Please give some ideas to proceed.

    Thanks.
  • #757665
    Hi Abhijith,

    Find the attached example.
    Hope it will be helpful for you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "If you can dream it, you can do it."

    AsyncWCF.rar

    Delete Attachment

  • #757672
    Hi,

    Check these links for Fault Exceptions in WCF

    http://www.dotnetspider.com/resources/43668-Handling-Exceptions-WCF-Applications.aspx

    http://www.codeproject.com/Articles/376303/Fault-Contract-Handling-Errors-in-WCF-and-A-Very-S

    http://geekswithblogs.net/LeonidGaneline/archive/2008/05/07/wcf-availability-of-the-wcf-services.aspx

  • #757704
    Hi Guys,

    I will be using IAsyncResult for this and by the way i there is no problem of getting the errors in client side. The problem is while throwing an exception to the caller layer and if i check it in CallStack i did not find the caller methods.

    So Question is -

    1) How can i throw the exception to the caller method in different layer in IAsyncResult. ?

    Thanks & Regards,
    Abhijith

    Mail - abhijith.pn@gmail.com
    Check My Blog - http://www.solvemytechissue.in/


  • Sign In to post your comments