Exceptions thrown by Web Services

Discussion in 'ASP .Net Web Services' started by Water Cooler v2, Feb 24, 2006.

  1. When a Web Service throws an exception to the caller/client, the
    exception is always cast to SoapException regardless of the actual type
    of the exception thrown. In such a scenario, how would you think it is
    appropriate for a Web services client to determine the exact type of
    exception?


    Consider this example.


    CLIENT
    class Client
    {
    [STAThread]
    static void Main(string[] args)
    {
    using(localhost.ExceptionThrowerService ets = new
    ExceptionCatcher.localhost.ExceptionThrowerService())
    {

    try
    {
    ets.throwCustomException();
    }
    catch(System.Exception e)
    {
    /*How would you determine here whether the type of e is
    MyCustomException or some other one
    Given that MyCustomException is given inside the Web service.*/
    Console.WriteLine(e.GetType().ToString());
    }
    Console.ReadLine();
    }
    }
    }



















    SERVER
    namespace ExceptionThrower
    {
    public class ExceptionThrowerService : System.Web.Services.WebService
    {

    [WebMethod]
    public void throwCustomException()
    {
    Trace.WriteLine("Throwing custom exception now.");
    throw new MyCustomException();
    }
    } //End of class ExceptionThrower


    public class MyCustomException: System.Exception
    {
    private string mDetail = "I am the best guy.";

    public MyCustomException()
    {
    mDetail = "I am *still* the best guy.";
    }

    public MyCustomException(string lDetail)
    {
    this.Detail += ("\n" + lDetail);
    }

    public string Detail
    {
    get
    {
    return mDetail;
    }
    set
    {
    mDetail = value;
    Trace.WriteLine("Setting the value of mDetail...");
    }
    }

    }//End of class MyCustomException

    }
    Water Cooler v2, Feb 24, 2006
    #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. Winista

    Unhandled Exceptions thrown

    Winista, Mar 22, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    401
    Winista
    Mar 22, 2006
  2. Adam Maass
    Replies:
    5
    Views:
    404
    Sudsy
    Jul 22, 2003
  3. Mike Schilling
    Replies:
    2
    Views:
    352
    Mike Schilling
    Jul 16, 2003
  4. John
    Replies:
    4
    Views:
    443
  5. Sergei Shelukhin

    handling exceptions thrown by web service methods ON THE SERVER

    Sergei Shelukhin, Feb 9, 2007, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    114
    Teemu Keiski
    Feb 15, 2007
Loading...

Share This Page