locked
consequences of using ServiceContract everywhere RRS feed

  • Question

  • Hi,

    I wrote a library which contains certain interfaces that, in the future i might like to use as wcf contracts. Is it a good idea to just assign the ServiceContract attribute, even if in 9/10 cases i won't use it as one? Or should i just copy the interface for the cases i do want to use it as ServiceContract?

    Not sure which consequences using ServiceContract could have... (i am wondering the same for DataContract attribute)

    Thank you!


    Monday, April 18, 2011 8:19 AM

Answers

  • Hi,

    Well what i mean is that decorating your interface with attributes which have no real meaning would make you interface more complex then needed. So only add the attribute to the interface which you realy want to expose as a service. So interfaces who will not be used as service contracts don't decorate them with the attributes.

    I think that the servicecontract attribute have no consequences on your interface, so you can make your interfaces also your servicecontracts. So don't make a copy , just reuse your interface.

    Regards,

    Dennis

    • Marked as answer by JaLaCom Wednesday, April 20, 2011 1:54 PM
    Tuesday, April 19, 2011 11:39 AM

All replies

  • Hi Lammers,

    I would advise to only add the servciecontract attribute to your interface when needed. As far as i know there are no negative consequences when you add this attribute with the service operation attributes to your interface. For your datacontracts i could be a different situation. i wrote a post about that. When you have a domain objects which contains methods and properties i would advise to create separate datacontracts and use mappings to you domain objects. This give you way more flexibility.

    http://dennisvandelaar.net/2011/04/06/wcf-services-and-shared-assemblies/

    Regards,

    Dennis

    Monday, April 18, 2011 9:09 AM
  • Hi,

    Thank you for your answer, though it's not 100% clear for me:

    About servicecontract I do not understand what you are saying. First you tell it's adviced to add them only if you actually need it, and then that is has no negative concequenses.

    And in case I should only add it when i need it, i should just copy the interface and add the attributes to the copy? Or is there a way which doesn't require me to change two interfaces when i want to change the interface?

    Thank you.

    Tuesday, April 19, 2011 10:56 AM
  • Hi,

    Well what i mean is that decorating your interface with attributes which have no real meaning would make you interface more complex then needed. So only add the attribute to the interface which you realy want to expose as a service. So interfaces who will not be used as service contracts don't decorate them with the attributes.

    I think that the servicecontract attribute have no consequences on your interface, so you can make your interfaces also your servicecontracts. So don't make a copy , just reuse your interface.

    Regards,

    Dennis

    • Marked as answer by JaLaCom Wednesday, April 20, 2011 1:54 PM
    Tuesday, April 19, 2011 11:39 AM
  • I believe if you specify such attributes there is no harm and it will be helpful for you later when you decide to expose them as WCF service. You will just need to make some changes in config and rest everything will already be there.

    So I feel you should specify these attributes.

    Tuesday, April 19, 2011 12:08 PM