"Tomsawyer2kin_ hotmail" <To************ *******@discuss ions.microsoft. com>
wrote in message news:6B******** *************** ***********@mic rosoft.com...
Hi,
I created a custom Exception Class as
Public Class CSTException : Inherits System.Applicat ionException
' required to over ride the base class method
Sub New(ByVal ExceptionCode As AppExCodes)
MyBase.New(CStr (ExceptionCode) )
End Sub
end class
in my WS i have a reference to the class and i throw a CSTException.
In my client side i have the reference to the CSTException class too.
I use a try catch as
try
...
catch ex as CSTException
...
end try
Now on my client side i get the ex as a SoapException obj . and the
ex.Message as
"Server was unable to process the request ---257" where 257 is my
AppExCode.
I was expecting ex.Message to be "257".
Is theer any way i can prevent my customexception class to be thrown as
wrapped inside a SoapException?
No. This is by design. There's no such thing as an Exception in Web
Services. There are Soap Faults. Since .NET gives you no way to map
exceptions into faults, all unhandled exceptions are translated into Soap
Faults.
The best you can do involves manually creating your WSDL file and adding
faults. Then, when you need to throw an exception corresponding to one of
the faults, you create the body of the fault and place it in the Detail
property of the SoapException, then throw it.
A .NET client will still receive a SoapException on the other end, but will
have still have the fault body in the Detail property. If you like, your
custom client code can look at the Detail and throw a custom exception
(passing the original as InnerException, please).
John