WCF - Finding Best Practices with Multiple Contracts Using Common Methods

I intend to have one main module that displays the interfaces with which other large modules (different clients) will interact. If, say, there is a group of methods:

void Method_A();
void Method_B();
void Method_X1();

to open one type of client (module "X1") and:

void Method_A();
void Method_B();
void Method_X2();

to show other types of clients (module "X2") and knowing that Method_Athey Method_Bmust have an exact implementation ... whereas how can I best design a service architecture (in terms of services and contracts)?

Is it possible to implement Method_A and Method_B ​​only once (not 2 times in different contract implementations)?

How do I use interface inheritance when using WCF?

, , , !

@marc_s... ...

+5
2

, , IServiceBase ServiceBase, Method_A Method_B, , , ServiceBase Interface1 Interface2. :

[ServiceContract]
public interface IServiceBase
{
    [OperationContract]
    void Method_A();

    [OperationContract]
    void Method_B();
}

[ServiceContract]
public interface IService1 : IServiceBase
{
    [OperationContract]
    void Method_X1();
}

[ServiceContract]
public interface IService2 : IServiceBase
{
    [OperationContract]
    void Method_X2();
}

public abstract class ServiceBase : IServiceBase
{
    void Method_A()
    {
        ... implementation here ...
    }

    void Method_B()
    {
        ... implementation here ...
    }
}

public class Service1 : ServiceBase, IService1
{
    void Method_X1()
    {
        ... implementation here ...
    }
}

public class Service2 : ServiceBase, IService2
{
    void Method_X2()
    {
        ... implementation here ...
    }
}
+3

!?!?!:-)

public interface IServiceA
{
  void Method_A();
  void Method_B();
  void Method_X1();
}

public interface IServiceB
{
  void Method_A();
  void Method_B();
  void Method_X2();
}

.

MethodAHandler MethodBHandler , ( ), - :

using MethodHandlers;  // contains the two method handlers

public class ServiceA : IServiceA
{
   public void Method_A()
   {
       MethodAHandler hnd = new MethodAHandler();
       hnd.HandleMethodCall();
   }

   public void Method_B()
   {
       MethodBHandler hnd = new MethodBHandler();
       hnd.HandleMethodCall();
   }

   public void Method_X1()
   {
       // handle method X1 call here or delegate to another handler class
   }
}

:

using MethodHandlers;  // contains the two method handlers

public class ServiceB : IServiceB
{
   public void Method_A()
   {
       MethodAHandler hnd = new MethodAHandler();
       hnd.HandleMethodCall();
   }

   public void Method_B()
   {
       MethodBHandler hnd = new MethodBHandler();
       hnd.HandleMethodCall();
   }

   public void Method_X2()
   {
       // handle method X2 call here or delegate to another handler class
   }
}

.NET, , .

+2

All Articles