none
How to handle error codes from a service? RRS feed

  • Question

  • Hi ,

    I have implemented a client that connects to a service and if any error occurs it returns only 

    major, mojor.minor and major.minor1.minor2 combinations. Is there any particular API 

    to handle these or this should be done or manually handled ? How can we handle these 

    error codes? or can I use a Resource file to fo this?


    Roopini


    • Edited by Roopini Friday, April 4, 2014 4:52 AM
    Friday, April 4, 2014 4:15 AM

All replies

  • Can you help us understanding bit more on “major, mojor.minor and major.minor1.minor2 combinations”?

    WCF is a very extensible framework. You can explicitly control the behavior of your application when an exception is thrown. You can

    • Decide to send a fault to the client or not,
    • Replace an exception with a fault,
    • Replace a fault with another fault,
    • Perform logging,
    • Perform other custom activities

    There is no API on this, but you can use FaultException Class and populate the Error Code by writing just a single line of code as below,

    Service Code

    public void Operation()
        {
            try
            {
                // Access a database …
            }
            catch (DbException e)
            {
                throw new FaultException(
                    new FaultReason(e.Message),
                    new FaultCode(“Data Access Error”));
            }
        }
    }

    Here you can use your own Fault code or Map that with a WCF Error Code.

    Client

    public class Client
    {
      public void InvokeOperation()
      {
        IService service = // Obtain service proxy…
        try
        {
          service.Operation();
        }
        catch (FaultException e)
        {
          if (e.Code.Name == “Data Access Error”)
          {
            Console.WriteLine(“Handling data access exception {0}”, e.Reason);
          }
        }
      }
    }

    Refer:http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/

    http://msdn.microsoft.com/en-us/library/vstudio/hh323726%28v=vs.100%29.aspx

    http://blogs.msdn.com/b/pedram/archive/2008/01/25/wcf-error-handling-and-some-best-practices.aspx



    Lingaraj Mishra


    Friday, April 4, 2014 5:37 AM
  • Hi,

    major, mojor.minor and major.minor1.minor2  are the error code combinations.

    001,001.0120,0102.0404.0132 are the number combinations of error codes. These

    codes are customized error codes that are obtained from the service.

    For now we handling something like this

     #region major = 0101
                            else if (response.major.code == "0101")
                            {
                                FormatUserMessages_Extn(mobjLanguage.ERR_VIS_SERVICE_GENERIC_ERROR + mobjLanguage.CONTACT_INFO_WITH_MAIL, partnumber, mobjLanguage.ERR_VIS_SERVICE_ERROR_HEADER, strMajorCode, MyMessageBoxIcon.ERROR);
    
                            }

    but we feel that it is tedious job to handle every combination where there are more than 60 combinations of error codes.


    Roopini


    • Edited by Roopini Friday, April 4, 2014 6:10 AM
    Friday, April 4, 2014 6:06 AM