adam
adam

Reputation: 2970

Server returns 500 code but can't trap error

I have an ASP.NET web service running in IIS, on a Windows 2003 server.

Here are the IIS logs for a call I had done using another .NET program. It correctly responded to my application with "Hello World"

2013-03-25 19:38:36 W3SVC1406312275 VMC-MMS 192.168.1.223 POST /test.asmx wsdl/mex 80 - 172.16.129.193 HTTP/1.1 - - - webservices.vm.vmc 500 0 0 775 677 1671
2013-03-25 19:38:36 W3SVC1406312275 VMC-MMS 192.168.1.223 GET /test.asmx wsdl 80 - 172.16.129.193 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+2.0.50727.5466) - - webservices.vm.vmc 200 0 0 3103 183 2531
2013-03-25 19:38:36 W3SVC1406312275 VMC-MMS 192.168.1.223 POST /test.asmx wsdl 80 - 172.16.129.193 HTTP/1.1 - - - webservices.vm.vmc 500 0 0 775 645 250

Here is the IIS log for a call done from an RPG program... which is sending back "500" "Internal Server Error"

2013-03-25 21:10:26 W3SVC1406312275 VMC-MMS 192.168.1.223 POST /test.asmx - 80 - 192.168.1.6 HTTP/1.1 http-api/1.24 - - webservices.vm.vmc 500 0 0 697 32968 2421

------------------

------------------

My Global.asax Application_Start and Application_Error are both coded to log a message when they are hit.

Calls from both .NET and RPG write to the log file in the Application_Start function... but neither writes to the log in the Application_Error function.

HelloWorld only initializes a logger and returns the string "Hello World". And... the log is getting written in both calls.

So... how do I trap whatever error is occurring? which is sending back the 500 code.

Upvotes: 1

Views: 3037

Answers (1)

rsbarro
rsbarro

Reputation: 27359

Unfortunately, Application_Error does not fire for unhandled exceptions in web services.

Check the answers to this question for more information. You're going to have to do something like either add a try-catch to each web method, or create a SOAP extension to handle the web service exceptions.

I would probably go the SOAP extension route and create an extension I could use in all my projects as a generic web service exception handler.

UPDATE
One of the answers to this question has a SOAP extension code example.

Upvotes: 1

Related Questions