Application_error exceptions that cannot be caught
[Webmethod]Public StringHelloworld (){Throw NewException ("This exption can't be handled by application_error method");Return "Hello World";}
Defining application_error will not capture this exception.
The reason is that you need to know the lifecycle of the SOAP request in ASP. NET.
If the process message process calls webmethodSoapexception,SoapheaderexceptionAfter being serialized, return at the soap <fault> node.
Exceptions in the process message process are handled using the soap extended extension.
We can process soap extension.
Code
Public Class Soapexceptionhandler: system. Web. Services. Protocols. soapextension
{
Public Override Void Processmessage (system. Web. Services. Protocols. soapmessage message)
{
If (Message. Stage = Soapmessagestage. afterserialize)
{
If (Message. Exception ! = Null )
{
Logutil. log. Error (message. Exception. innerexception );
}
}
}
Public Override Object Getinitializer (type servicetype)
{
Return Null ;
}
Public Override Object Getinitializer (
Logicalmethodinfo methodinfo,
Soapextensionattribute)
{
Return Null ;
}
Public Override Void Initialize ( Object Initializer)
{
}
}
Configure in the web. config system. Web Node
Code
< WebServices >
< Soapextensiontypes >
< Add Type = "Elplan. App. soapexceptionhandler, elplan. app" Priority = "1" Group = "High" />
</ Soapextensiontypes >
</ WebServices >
Debugging:
If you use vs to directly run and debug asmx, it is not possible (because it is not a complete SOAP request.) You can use webservicestudio.
Address: http://www.codeplex.com/WebserviceStudio
ReferenceArticle:
using soap extensions in ASP. Net
handling and throwing exceptions in XML Web Services
how to create a global exception handler for a Web Service