Exceptions thrown by Web Services

W

Water Cooler v2

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

}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top