Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-using an existing interface as a WCF Interface. Does contract decoration affect existing applications? Is there any harm?

I have a scenario where I have an existing interface that I would like the WCF service to implement.

The main goal is to allow us to be able to use dependency injection such that the implementation can be injected as a WCF service or a local assembly.

E.g.

Existing interface

public interface IStuffDoer
{
   bool DoStuff(string parameter);
}

Now I need a WCF Service contract of type IStuffDoer. An option that I can think of is

[ServiceContract]
public interface IStuffDoerService: IStuffDoer
{

}

But then note that the existing interface does not have its operations decorated by either [ServiceContract] or [OperationContract] attributes.


Since one cannot override parent interface method signatures, my only option(as far as I know) is decorating the original interface with WCF contract attributes, like so:

[ServiceContract]
public interface IStuffDoer
{
   [OperationContract]
   bool DoStuff(string parameter);
}

Is there any harm in doing so?

What is the impact on existing, non-WCF applications or that are making use of that contract?

If it impacts them somehow, what would be my best option?

like image 456
user919426 Avatar asked Dec 28 '25 02:12

user919426


1 Answers

What is the impact on existing, non-WCF applications or that are making use of that contract?

There is not impact. It's still the same interface. The attributes don't do anything on their own. You can decorate your interface with them and still use it as a "normal" interface.

like image 190
nvoigt Avatar answered Dec 30 '25 17:12

nvoigt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!