I have a base interface that is inherited by several other interfaces. This interface has one method:
[ServiceContract]
public interface IBase
{
[OperationContract]
List<short> GetShorts();
}
I then, of course, have an inheriting interface:
[ServiceContract]
public interface IUseful : IBase
{
[OperationContract]
List<MyObject> GetMyObjects(MyInput input);
}
I have a class that serves as a generic interceptor for interfaces in order to provide a simple way to call services without extra setup:
public class ServiceInvoker<T> : DynamicObject, IInterceptor
where T : class
{
// ...
public T Client { get { return (dynamic)this; } }
// ...
}
I want to be able to call any service that implements IBase
, so I have a class that looks like this:
public class BaseCaller
{
private readonly IBase _base;
public BaseCaller(IBase base) { _base = base; }
public List<short> GetShorts() { return _base.GetShorts(); }
}
I construct BaseCaller
basically like this:
var si = new ServiceInvoker<IUseful>();
var bc = new BaseCaller(si.Client);
The problem comes when I make a call to GetShorts
and it calls _base.GetShorts
:
MissingMethodException
Method 'MyApp.IUseful.GetSubNumbers' not found.
When I hover over _base
, I can see the interceptor, and I can see that token_GetSubNumbers
exists. I can cast _base
to IUseful
and call GetMyObjects
successfully; I just can't call GetShorts
. It looks like Castle isn't implementing IBase
. Am I doing something wrong?
This appears to work, so going with it unless someone provides a better solution:
I removed the inheritence of IBase
and just use it directly with a ServiceInvoker<IBase>
. The services now have to implement IBase
directly and expose an endpoint for it, but it works.