The WebService method is called on the client to process the business process. If the business processing program returns an error, we can generally return the processing result to the customer segment by returning the error code, the customer segment carries out corresponding error processing for different error codes. According to this process, sometimes the client may need a lot of repeated code to respond to different error codes. A simple example is, different error messages are displayed for different error codes. In some systems, the error messages processed by the business may be stored in the business database. In this case, the customer segment must display the error message, you must also call the corresponding Service to obtain the error message.
WebService uses the Detail of SoapException to provide the client with the ability to return more detailed error information or business-related information. For example, in an authentication example, the following code can be used to return an exception to the client segment, inform the customer of the error codes, error messages, and other relevant information.
Private static int Authenticate (CredentialSoapHeader header)
{
Int iRet;
Try
{
SqlConnection conn = new SqlConnection (CommonDB. ConnectionString );
SqlCommand cmd = new SqlCommand ("P_Employee_Check", conn );
Cmd. Parameters. Add ("@ EmployeeCode", header. Username );
Cmd. Parameters. Add ("@ EmployeePassword", header. Password );
Cmd. Parameters. Add ("@ ReturnValue",-1 );
Cmd. Parameters ["@ ReturnValue"]. Direction = ParameterDirection. ReturnValue;
Cmd. CommandType = CommandType. StoredProcedure;
Conn. Open ();
Cmd. ExecuteNonQuery ();
Conn. Close ();
IRet = Convert. ToInt32 (cmd. Parameters ["@ ReturnValue"]. Value );
}
Catch (Exception ex)
{
IRet = 1000;
Throw new SoapException (string. Empty, SoapException. ServerFaultCode, "Service", ErrorMessage. CreateSoapExDetail (iRet, "database operation exception .." + ex. Message ));