You can use interfaces in service contract definitions, if you really want to, as long as you include known types as you do (with a little tweaking, see below).
Apparently, using an interface as a type parameter makes it too big for C # 3.0. I changed the known type attribute to
[ServiceKnownType(typeof(Batch<Command>))] public interface IActions { }
It makes it work. Serialization and deserialization will work, but then you came across this exception:
It is not possible to pass an object of type 'Batch`1 [Command]' to enter "IBatch`1 [ICommand]".
For this to work, you need language support for the general type of covariance that was introduced in C # 4.0. For it to work in C # 4.0, however, you need to add a dispersion modifier:
public interface IBatch<out T> { }
Then it works fine ... unfortunately you are not using C # 4.0.
The last thing about using interfaces in your service contract: if you create a service link from them, it will enter all the interface parameters as object , because the original type of interface is not part of the metadata. You can share the contracts using the assembly link or manually reorganize the generated proxy server to fix it, but overall, using WCF interfaces is probably more of a problem than it costs.
Thorarin
source share