문제

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

도움이 되었습니까?

해결책

You can check check the Descriptions servicetype property:

var serviceType = host.Description.ServiceType

다른 팁

Check as below :

typeof(ServiceContract) == host.Description.ServiceType
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top