Calling WebService with using and try catch

Discussion in 'ASP .Net Web Services' started by homawong@gmail.com, Nov 19, 2005.

  1. Guest

    Hi,

    This seems to be an obvious question but I ask anyway.

    Currently, I call webservice as follow,

    try
    {
    using (webService.someService ws = new .webService.someService())
    {
    // Do something
    }
    }
    catch (System.Net.WebException ex)
    {
    // Catch exception
    }

    Sometimes I want to get some information about the webservice within
    the catch block, so this structure prevent me from doing it and I have
    to add another using(...) block within the catch code.

    One simple way to get around it is swapping the try/catch and using,

    using (webService.someService ws = new .webService.someService())
    {
    try
    {
    // Do something
    }
    catch (System.Net.WebException ex)
    {
    // Catch exception
    }
    }

    my question is when an unhandled exception is thrown, the using(...)
    block should "theorically" effective and clean up the webservice
    correctly. But would there be things that might happen causing the
    clean up of webservice fail? If this is the case, then with using
    outside of try/catch might not be a good idea.

    But if there is such things, I think the original one will also fail.
    Any idea on this?

    Homa Wong
    , Nov 19, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dan
    Replies:
    2
    Views:
    6,009
  2. bienwell
    Replies:
    4
    Views:
    3,711
    bienwell
    May 27, 2005
  3. judith
    Replies:
    16
    Views:
    1,056
    Chris Uppal
    Oct 16, 2006
  4. Replies:
    6
    Views:
    353
  5. Victor Hooi
    Replies:
    6
    Views:
    92
    Neil Cerutti
    Nov 20, 2013
Loading...

Share This Page