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.