Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programatically discover a ServiceHost's Service Type

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...

like image 768
Spence Avatar asked May 08 '26 21:05

Spence


2 Answers

You can check check the Descriptions servicetype property:

var serviceType = host.Description.ServiceType
like image 194
Dominik Avatar answered May 11 '26 11:05

Dominik


Check as below :

typeof(ServiceContract) == host.Description.ServiceType
like image 21
Upendra Chaudhari Avatar answered May 11 '26 10:05

Upendra Chaudhari