none
What are the reasons that we can not use an abstract class to define Service Contract ? RRS feed

  • Question

  • There are lot of answers, but nothing clear to me.

    Why can't we use abstract class in place of interfaces in WCF Service Contracts?  

    1) Is it because the "ServiceContractAttribute" is marked as "Sealed" and it can not inherit?  Is it by Design ? What is the reason behind it?

    2) Any other reason ?

    Thursday, December 26, 2013 5:30 PM

Answers

  • Hi,

    If we use an abstract class, it will compile correctly but at runtime we will get an error like "Contract inheritance can only be used among interface types."

    EDIT:
    It will work if we include the [ServiceKnownType] (on a Service Contract) or [KnownType] on a Data Contract. Basically we have to tell WCF what to serialize/deserialize.

    For more information, please try to check:
    #Can we use abstract class instead of interface with service contract in WCF:
    http://dotnetinteviewquestions.blogspot.in/2013/08/can-we-use-abstract-class-instead-of_10.html .

    Best Regards,
    Amy Peng


    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.

    Friday, December 27, 2013 7:01 AM
    Moderator