Please tell me if this is possible. I have a client win form app and a wcf app in C#. This is my model.
public interface IServiceA
{
Your code as written generates a warning because the IGetData
DoWork()
method hides the IServiceA
DoWork
method.
To get rid of the warning you need to add the new keyword:
[ServiceContract]
public interface IGetData : IServiceA
{
// Implements IServiceA method
[OperationContract]
new string DoWorkA();
}
But I think what you want to do is to aggregate smaller interfaces into one larger service. Then your modules can interact with their easy to understand interface (which is a subset of the service interface).
For example:
public interface IWarehouse : IShipping, IReceiving, IInventory, IMovement {}
We implemented something similar.
The clients could then interact with client proxies with a simpler subset of the entire service interface.
First define the interfaces:
[ServiceContract]
public interface IServiceA
{
[OperationContract]
string DoWorkA();
}
[ServiceContract]
public interface IServiceB
{
[OperationContract]
string DoWorkB();
}
[ServiceContract]
public interface IGetData : IServiceA, IServiceB
{
}
Then create the proxies (you could also use ChannelFactory
here):
public class ServiceClientA : ClientBase<IGetData>, IServiceA
{
public string DoWorkA()
{
return Channel.DoWorkA();
}
}
public class ServiceClientB : ClientBase<IGetData>, IServiceB
{
public string DoWorkB()
{
return Channel.DoWorkB();
}
}
The above would be analagous to your MyClass.
Then the client can use the individual interface:
IServiceA clientA = new ServiceClientA();
string result = clientA.DoWorkA();
IServiceB clientB = new ServiceClientB();
result = clientB.DoWorkB();
You could also create a service factory here if you wanted.
I hope that gives you some ideas.
Couple of points:
To answer your point where you have lots of module which need to get data from service, can you categorize these modules in business/function nature? If yes, then you can create different WCF service for each of those business/function and respective modules will call respective service. Further to this I don't see a point why one module should not be allowed to gather data from more than one service. That is perfectly acceptable scenario.
HTH