1

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.

Community
  • 1
  • 1
lintmouse
  • 5,079
  • 8
  • 38
  • 54
  • 1
    You are considering using assembly with contracts on both client and server? Normally ISchedulerJob (don't forget about DataContract attribute for job-classes) should present data for interchange with service, not methods. Methods are not serialized. – SalientBrain Mar 03 '13 at 16:41
  • Yeah, I hear you. I ended up pushing the logic to create the ISchedulerJob to the server and used a method with some basic data contract stuff that the client could pass in. – lintmouse Mar 06 '13 at 02:43

0 Answers0