Capturing WebService exceptions using SOAP extensions in ASP.

Source: Internet
Author: User

Original: Capturing WebService exceptions using SOAP extensions in ASP.

Application_Error exceptions that cannot be caught

      [WebMethod]         Public string HelloWorld ()        {            thrownew Exception ("This exption can ' t is handled by Application_ Error Method ");            return "Hello World";        }
Defining Application_Error will not catch this exception.
Reason needs to understand the lifetime of the SOAP request in the ASP.
   

If SoapExceptionis generated when the process message procedure calls WebMethod,SoapHeaderException is serialized and returned in the soap <Fault> node.

Exceptions generated by process message procedures using the SOAP extension extension
We can handle the SOAP extension.

Code
Public classSoapExceptionHandler:System.Web.Services.Protocols.SoapExtension
{
Public Override voidProcessMessage (System.Web.Services.Protocols.SoapMessage message)
{
if(message. Stage==soapmessagestage.afterserialize)
{
if(message. Exception!= NULL)
{
LogUtil.Log.Error (message. Exception.innerexception);
}
}
}

Public Override ObjectGetInitializer (Type servicetype)
{
return NULL;
}

Public Override ObjectGetInitializer (
LogicalMethodInfo MethodInfo,
SoapExtensionAttribute attribute)
{
return NULL;
}

Public Override voidInitialize (Objectinitializer)
{
}
}
configuring in the Web. config system.web node
Code
        <webservices>
<soapExtensionTypes>
<Addtype= "Elplan.App.SoapExceptionHandler, Elplan.app" Priority= "1"Group= "High" />
</soapExtensionTypes>
</webservices>

Debugging:

It is not possible to run debug asmx directly with vs. (Because ...) It is not a complete SOAP request.) Webservicestudio can be used.
Related address: Http://www.codeplex.com/WebserviceStudio

Reference article:

Using SOAP Extensions in ASP.
Handling and throwing Exceptions in XML Web Services
How to create a global exception handler for a Web Service

Capturing WebService exceptions using SOAP extensions in ASP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.