2

G'day,

I've tried searching MSDN and here, but I don't think I can do this:

Given a reference to a ServiceHost, is it possible to discover the type of the host it is executing?

Something like

ServiceHost host = new ServiceHost(typeof(MyContractImplementation));
Type serviceType = host.MagicCallHere();
Assert.True(typeof(MyContractImplementation) == serviceType);

Does MagicCallHere exist?

Bonus marks if you can dodge reflection...

Spence
  • 28,526
  • 15
  • 68
  • 103

2 Answers2

7

You can check check the Descriptions servicetype property:

var serviceType = host.Description.ServiceType
Dominik
  • 3,342
  • 1
  • 17
  • 24
3

Check as below :

typeof(ServiceContract) == host.Description.ServiceType
Upendra Chaudhari
  • 6,473
  • 5
  • 25
  • 42