Search code examples
asp.netweb-servicesasmx

How do I generate a 500 error within an ASMX web method?


I have an ASMX web service that provides various search utilities. If my user inputs too little search criteria, I want to have the web service return an HTTP 500 with a custom message. How do I do this? I do not want to handle the insufficient input on the client side because of in-browser manipulation abilities.


Solution

  • HTTP 500 means internal error. Throwing an unhandled exception should give you a HTTP 500.

    throw new Exception("Your error message");
    

    However, it is probably not a good idea to do this.

    A better approach would be to throw a SOAP fault.