none
Wcf REST WebFaultException Error RRS feed

  • Question

  • Hi.

    I have created a WCF REST Services.

    I handled Exception Using Fault Exception But I am Getting Error Plz Help...

    DataContract :

       [DataContract(Name = "FaultException", Namespace = "http://www.services.in/services/faultexception")]
        public class ServiceFaultException
        {
            [DataMember(Name = "ErrorOccouredLevel", Order = 1)]
            public string ErrorLevel { get; set; }
            [DataMember(Name = "ErrorMessage", Order = 2)]
            public string ErrorMessage { get; set; }
        }

    Error handling:

    catch (Exception ex)
    {
        ServiceFaultException _sfexception = new ServiceFaultException()
          {
             ErrorLevel = "003",
             ErrorMessage = ex.Message.ToString()
           };
    throw new FaultException<ServiceFaultException>(_sfexception);
    }

    But It Shows The Error:



    Kartikeyan

    Friday, February 22, 2013 7:06 AM

Answers

  • Hi

    I solve the by means of another way.

    But I dont know It is a Advisable to throw the exception and don't Know How long it Supports. But Now for the present it solves my problem

    SVC Code

    catch (Exception ex)
                {               
                        OutgoingWebResponseContext _webresponse = WebOperationContext.Current.OutgoingResponse;
                        _webresponse.Headers.Add("error", ex.Message.ToString());
                        return null;
                    }

    And Client Side is

    HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
         if(resp.Headers.AllKeys.Contains("error"))
           {
             int _index = Array.IndexOf(resp.Headers.AllKeys, "error");
             throw new Exception(resp.Headers.Get(_index));
             }

    The last and Long Exception I thrown is. 

    You are an InActive Employee, Please Verify with your team head. About Re-Activation


    Kartikeyan



    Saturday, February 23, 2013 1:46 PM

All replies

  • Please change the fault contact code as like this and check.

    throw new FaultException<ServiceFaultException>(_sfexception,Ex.ToString());


    With Thanks and Regards
    Sambath Raj.C
    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you
    Happy Programming!

    Friday, February 22, 2013 12:02 PM
  • Hi Sambath 

    Again Same Exception Unhandled by User Code Error


    Kartikeyan

    Friday, February 22, 2013 12:19 PM
  • Hi

    I solve the by means of another way.

    But I dont know It is a Advisable to throw the exception and don't Know How long it Supports. But Now for the present it solves my problem

    SVC Code

    catch (Exception ex)
                {               
                        OutgoingWebResponseContext _webresponse = WebOperationContext.Current.OutgoingResponse;
                        _webresponse.Headers.Add("error", ex.Message.ToString());
                        return null;
                    }

    And Client Side is

    HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
         if(resp.Headers.AllKeys.Contains("error"))
           {
             int _index = Array.IndexOf(resp.Headers.AllKeys, "error");
             throw new Exception(resp.Headers.Get(_index));
             }

    The last and Long Exception I thrown is. 

    You are an InActive Employee, Please Verify with your team head. About Re-Activation


    Kartikeyan



    Saturday, February 23, 2013 1:46 PM