0

I'm trying to throw custom exception from a web service and trap it on the client side. I'm using JQuery and getting the JSON-serialized exceptions, so that's a good start. However the problems are:

  • Stack trace is sent to the client which i don't want.
  • I need to add an error code in addition to the exception message.

I've tried creating a custom exception, but it's omitting the error code when serializing.

1
  • What kind of web service? ASMX or WCF? Commented Jan 30, 2011 at 1:53

1 Answer 1

1

To send your own data back with a SoapException, you need to set the Details property on the SoapException object. Sorry I don't have my source code in front of me, but I believe you have to pass the details as a string to the SoapException object. I subclassed the SoapException object, passing its constructor the details I want. It then calls the SoapException constructor passsing the details along with some standard stuff I always want returned (it check the .Data property of the exception and adds it to the details). It turn all the stuff into XML for the details. On the client side I check for XML in the fault details and then create a new JavaScript error object and add the details as properties, then throw it.

So pass the error code in the details to the SoapException constructor. Custom exception properties are ignores by SoapException.

To turn off the stack trace I belive you fiddle with web.config.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.