My application has 2 "services", let's say one is a basic (integer) calculator, and one is a floating point calculator. I express these as interfaces like so:
public interface IBasicCalculator
{
int Add( int a, int b );
}
public interface IFloatingPointCalculator
{
double Add( double a, double b );
}
I want to expose these via WCF. Unfortunately WCF seems to be very tightly tied to the notion that every possible operation you want to expose must go through one single service interface -- you can't share sessions between services, it is cumbersome from the client side as you need to create a seperate proxy for each one, there don't seem to be any "sub-services", etc...
So, I've gathered that I need to present a "combined" interface (one might also call it a facade), like this:
[ServiceContract]
public interface ICalculatorService : IBasicCalculator, IFloatingPointCalculator
{
[OperationContract(Name = "AddInt")]
new int Add( int a, int b );
[OperationContract(Name = "AddDouble")]
new double Add( double a, double b );
}
If I do this, then WCF exposes both methods to the client, which can call them, and it all actually works.
However, "inheriting the interfaces" like that seems to be ungainly. Particularly the new
int Add
and new
double Add
. Strictly speaking, new
on a method indicates hiding an underlying method, which I'm not actually doing at all. I can omit the new
, but then I just get compiler warnings which amount to "I think I'm hiding this method, you need to rename it method or put 'new' on it".
So, this is a 2-part question:
Am I on track with my 'combine everything into one interface' logic, or is there actually a way to expose "sub-services" or "multiple linked services" using WCF?
If this is what needs to be done, is there a better way?
Thanks!