none
Custom Objects not exposed after adding faultcontract<customerrorclass> RRS feed

  • Question

  • Hi,

    I want to throw some custom exception from the service. I am facing problem in it...

    After generating the service reference, i have found that, no data contract got exposed and more over i am unable to create the object for the service.

    Here is the code i did:

     [ServiceContract]
        public interface IService1
        {
            [FaultContract(typeof(MyExcep))]
            [OperationContract]
            string GetData(int value);
        }

    And Exception is: - 

     [Serializable]
        public class MyExcep : CommunicationException   
        {
            public MyExcep()
            { }
    
            public MyExcep(string msg)
                : base(msg)
            { }
    
            protected MyExcep(SerializationInfo info, StreamingContext ctxt)
                : base(info, ctxt)
            {
            }
        }
    

    And in the client:

    Case 1:

    I am getting error on creating the service reference and also other complex types are not also exposed on the client.

    I am doing by using "Add service reference". i have also replaced the "communicationexception" and tried by inherting from "exception" class. But no use. Same problem comes.

    Case 2:

    But without inheriting  from exception class and if i marked it as datacontract and using the throw new faultcontact<T> then everything works fine.

    May i know what i have did wrong and how to get it correct.

    Thanks in advance.. 


    NANDAKUMAR.T

    • Moved by Fred Bao Tuesday, February 3, 2015 7:50 AM WCF Related
    Tuesday, February 3, 2015 2:34 AM

Answers

  • Hello,

    For the FaultContract, there is an example describes its usage:

    Fault Contract

    You could check it, it also uses the DataContract to markup its exception class, I think this might be by designed.

    By the way, since this issue is related with WCF, I suggest you could post WCF related issues to the WCF forum, the current forum is used to post feedback, questions and suggestions related to Released (RTM) versions of WCF Data Services Framework (formerly known as ADO.NET Data Services and Project "Astoria").

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, February 3, 2015 7:36 AM