I am developing ASP.Net asmx web services. And at client side, if the request to server returns Http error code, like http 500, how could I know from web services client side (I use the automatically generated client proxy by using add web references)?
thanks in advance, George
George, since you are using async WS calls, you must implement exception handling in the call back method. Eg: Following is the sample code I developed to give a demo of async delegates.
If your WS call is throwing an exception, it only gets caught when you do an EndInvoke on the AsynResult. If you are using a fire & forget mechanism of async WS call, you wont call EndInvoke and hence exception will be lost. So always use callback mechanism when you need to catch exceptions Hope this helps :)
Let me know if you have any more doubts.
This is a commonly encountered problem because Web services tend only to send you a HTTP 500 (Internal server error) message on encountering an unhandled exception. I use a trick I found long back. Basically, you need to drill into the WebException using a StreamReader to determine the root cause of the exception.
Sample code: (Sorry, didn't have any C# code handy. Please use a converter)
Can be converted using the DeveloperFusion converter, which I highly recommend.
See a previous question, easy-way-to-catch-all-unhandled-exceptions-in-c-net.
For web services running under IIS, it would seem that you need to catch exceptions in all threads by implementing UnhandledExceptionModule.
You can set up tracing for your webservices, a how to is below from the MSDN:
http://msdn.microsoft.com/en-us/library/bb885203.aspx
If you have access to the server also, you can set up HealthMonitoring for example which will record any errors which occur on the server side, like you posted the 500 internal server error.
Health Monitoring - http://msdn.microsoft.com/en-us/library/ms998306.aspx
You also have the ever useful Event Viewer if you can remote or log into the server.
Hope this helps:
Andrew
Assuming you have Visual Studio import the webservice and you use the Microsoft Web Services Enhancement 3.0 library, it will probably look something like this:
Any errors will be returned inside the 'MyWebService.DoSomethingCompletedEventArgs' object.
You can get the info from e.Response.GetResponseStream(). As read said, you might need to look at the server side to get a more complete info.