none
Exposing an Interface to a client in a WCF Server.

    Question

  • I am writing a WCF Service.

    I am having a Products class which derives from a List collection. Now there are other classes which are similar to this class. So i am having an interface as IBase and all my classes implement this interface. When i implemented my service, i am able to access all my classes, but my IBase interface is not visible from client side. I am not able to mark interface as DataMember. Can anyone help me how to expose my interface to the client? IBase interface is not a service contract. It is just an interface which all my entity objects implement.

     

    Thanks and Regards,

    alilai

    Monday, July 14, 2008 1:05 AM

Answers

  • KnownType attribute is a way to ensure that the type data for teh contract is added to the wsdl metadata.  This only works for classes it will not work for an interface.  An interface cant store data and is not univerally understood by all languages out there so its not really exposable over wcf.

     

    Wednesday, July 16, 2008 5:38 PM
    Moderator

All replies

  • Sorry, but interfaces can not be exposed to a client via wsdl because an interace doesnt really expose data so it cant be a data contract.  Your only realy option is to expose a shared library between the client and server.  This shared library can be as rich as you want with interfaces and oteh classes.

     

    Tuesday, July 15, 2008 2:15 PM
    Moderator
  • There is a way to mention KnownType for a DataContract. Will that allow to expose the dependent Interfaces? Do

    have any idea about this. I am going to try this.

    Wednesday, July 16, 2008 5:34 PM
  • KnownType attribute is a way to ensure that the type data for teh contract is added to the wsdl metadata.  This only works for classes it will not work for an interface.  An interface cant store data and is not univerally understood by all languages out there so its not really exposable over wcf.

     

    Wednesday, July 16, 2008 5:38 PM
    Moderator
  • Thanks for the reply i got my answer

     

    Tuesday, July 22, 2008 12:08 AM
  • Hi - have a look at the below esp. from Marc Gravell - you can re-use the entity classes on both sides of the interface.

     

    Adding the [KnownType] attributes on any polymorphic base class should avoid most deserialization issues.

     

    http://www.vistax64.com/indigo/12092-how-serialize-generic-collections-wcf.html

    http://www.request-response.com/blog/PermaLink,guid,ff5fab81-affb-4b2b-aa67-c80bdfc86cbd.aspx

     

    Tuesday, July 22, 2008 9:49 AM
  • Well i am looling to share the Interface itself not the entity class. I am not sure if your links speaks about that.

     

    Thursday, July 24, 2008 8:53 PM