ExceptionHandling Web Services

  • Thread starter Thread starter muz dogru
  • Start date Start date
M

muz dogru

I have made own Exception classes, which extend from Exception. When I
throw a new MyException("my error message"), then catch the error and
print the message, it's all fine within an application. But when I throw
a new MyException in a Web Service and catch it on the "other side", I
only get the message that an Exception was thrown, but not the exact
error message.

How do I have to handle own Exceptions? Is there a good tutorial? Thanks
a lot.
 
Hi Muz!
I believe this is because webservices throw ONLY soap exception whenever
something go wrong within a webmethod so even if the error was something
like connection to DB error that the method try to accomplish , what is
thrown to the client is the soap exception so you might need to attach your
massage to that in your case . checkout this link, hope it helps
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemWebServicesProtocolsSoapExceptionClassTopic.asp
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
hello mohammas,

ok, it seems as if I have to throw a SoapException in every case. Thanks
for the link, that works fine, but the returned ErrorMessage is
something like:

System.Web.Services.Protocols.SoapException: invalid AccountId at
blabla.myThrow(SaferpayException e) in balblaWebService.asmx.cs:line 109
at blablaMethod(string message) in blabla.asmx.cs:line 56

This ErrorMessage is very long and I also don't want the user to know in
which file the exception occured. I just want them to see "invalid
AccountId". Isn't that possible?

Thanks,
Muz
 
Hi Muz
sorry i was away for a while , sure you can do that , you simply catch the
exception wrap it in your own user exception that has the custom message
that you what to display . hope that helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Back
Top