I have the following simple interface:
public interface IInitialisableWcfService
{
void Initialise();
}
Which I’m placing on a class that’s being used as a WCF service like so:
public class LocalResourceManager : ILocalResourceManager, IInitialisableWcfService
ILocalResourceManager is the interface that’s being used to set the binding configuration for the wcf endpoint.
Inside another class that we used for hosting WCF services on the fly, I have the following code that tests for the IInitialisableWcfService interface:
private void Create(Type serviceType)
{
try
{
ServiceHost host = null;
if (serviceType == typeof(IInitialisableWcfService))
{
// create object to initialize.
}
else
{
// do something else
}
catch (ThreadAbortException)
{
throw;
}
catch (Exception ex)
{
//log error
}
}
But this fails to match the LocalResourceManager manager service when it’s passed in, or indeed any other service that implements IInitialisableWcfService. I’ve also tried this
if(serviceType is IInitialisableWcfService)
But that doesn’t work either.
I’m not sure what the issue is here. Three possibilities:
1) The syntax for checking and interface is wrong. I find this unlikely.
2) Because the WCF endpoint is registered with an ILocalResourceManager interface, the object is not exposing its IInitialisableWcfService over WCF
3) Passing around a Type rather than an actual class means you can’t check for interfaces
Or possibly none of the above. Assistance greatly appreciated.
Cheers,
Matt
The
TypeofserviceTypeis the actual concrete type that’s implementing the service, so you just need to check if the service type is assignable to the interface you want: