Web services exception

Source: Internet
Author: User
Tags soap client

When web services raises an internal exception, the exception is transmitted to ASP. NET to determine how to handle it.
There are usually two types:
1) Send the exception to the HTTP client. ASP. NET returns an http internal server to the client.
ERROR (internal ERROR code: 500) message. The client processes the message.
2) Send exceptions to the SOAP Client
If the client uses the SOAP protocol, ASP. NET first uses it as a SOAP error and then returns it to the client.
When a client receives a SOAP error, its response method is similar to the previous one. The difference is that the SOAP agent triggers the SYSTEM
. WEB. SERVICES. PROTOCOLS. SOAPEXCEPTION. And set the value of SOAPEXCEPTION. CODE to SOAP.
The value of the incorrect FAULTCODE field (the default is a server error). Set the SOAPEXCEPTION. MESSAGE attribute
The value of the FAULTSTRIN field (the default value is the string of the stack trace that captures exceptions.
However, the disadvantage of this method is that no matter what exceptions are thrown by web services, the client throws SOAPEXCEPTION.
The solution does not allow ASP. NET automatically handles uncaptured client binding exceptions. web services must capture all application exceptions and explicitly throw a SOAPEXCEPTIONASP. NET will correctly use the soapexception code and MESSAGE attributes to fill in the FAULTCODE and FAULTSTRING elements of SOA errors. In this way, you can return custom error codes, these codes provide meaningful error information to the client. Then, the client can capture SOAPEXCEPTION and use SOAPEXCEPTION. the error CODE provided by the CODE attribute for proper processing. however, this is still flawed, that is, the client developers must know how to process the code, so they must put the information into the system documentation.
Custom error code
Public sealed class e1: ApplicationException
{
Public e1 (string message): base (message)
{
// Describe the error message. It does not do anything and depends on the base class.
// TODO: Add constructor logic here
//
}
}
Public sealed class e2: ApplicationException
{
Public e2 (string message): base (message)
{
// Describe the error message. It does not do anything and depends on the base class.

Related Article

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.