Click to See Complete Forum and Search --> : [RESOLVED] asp.net webservice throw exception


dannystommen
June 10th, 2009, 11:33 AM
I want to throw an 'nice' exception in asp.net

[WebMethod()]
public string testException(string key) {
if (key == "test"){
return "succeeds"
}
else{
throw new SoapException("Invalid key", SoapException.ClientFaultCode);
}
}



In client I recieve the a SoapException with message:
System.Web.Services.Protocols.SoapException: Invalid key
at MyProject.testException(String key) in ..myproject\my_service.asmx.cs:line 32


First of all, this doesn't look nice, and second, I don't want to show the stacktrace to the client.


I also use an 3th-party webservice. When an axception happens in this service, the message property of the SoapException is just the error message with out Exception type in the message and the stacktrace.

How to solve this?

hspc
June 10th, 2009, 02:30 PM
You need to edit web.config for the webservice:
configuration -> system.web -> customErrors: change mode attribute value to On.

dannystommen
June 11th, 2009, 03:05 AM
Works fine.

Thank you