I have a WCF service that will be used by .NET clients. I want to use an interface as a parameter in the operation contract. I haven't fully implemented the service to the point of being able to test this approach and I don't want to spend a lot of time on it if it turns out to be unfeasible.
Is this the correct way of doing this?
public interface ISchedulerJob
{
void Execute();
}
public class MyJobA : ISchedulerJob
{
public void Execute() { //... }
}
public class MyJobB : ISchedulerJob
{
public void Execute() { //... }
}
[ServiceContract]
[ServiceKnownType(typeof(MyJobA))]
[ServiceKnownType(typeof(MyJobB))]
public interface ISchedulerService
{
[OperationContract]
void Schedule(ISchedulerJob schedulerJob);
}
I checked out this post:
using class interface as a parameter in wcf service
It looks like what I'm trying to accomplish, but I get compile errors if I try to use the KnownType attribute on an interface so I went with the ServiceKnownType attribute instead.