I have some interface that is marked as a [ServiceContract] for WCF service.
But it’s also used in two different non WCF locations in my code.
The problem is that I am using a interface that is marked as a [ServiceContract] in not WCF projects.
Is there a way to have a this attribute only in a WCF context without duplicating code ?
Why are you using a WCF contract definition in places that are not WCF? the fact that its an interface is a WCF implementation detail. Define an interface that is not WCF related in your other code and then if it needs to talk to the WCF one then write an adapter that forwards to the WCF interface.
The additional benefit of this is that you provide an isolation boundary in that changes to the WCF contract do not have to bleed into your other code
also it allows different types to be used on IFoo and IWCFFoo so the DataContract DTOs don’t bleed in to the rest of your code