Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以编程方式发现ServiceHost';s服务类型_C#_.net_Wcf_Servicehost_Servicecontract - Fatal编程技术网

C# 以编程方式发现ServiceHost';s服务类型

C# 以编程方式发现ServiceHost';s服务类型,c#,.net,wcf,servicehost,servicecontract,C#,.net,Wcf,Servicehost,Servicecontract,G'day 我尝试在这里搜索MSDN,但我认为我无法做到: 给定对服务主机的引用,是否可以发现它正在执行的主机的类型 差不多 ServiceHost host = new ServiceHost(typeof(MyContractImplementation)); Type serviceType = host.MagicCallHere(); Assert.True(typeof(MyContractImplementation) == serviceType); 这里有魔法吗 如果您可以避

G'day

我尝试在这里搜索MSDN,但我认为我无法做到:

给定对
服务主机的引用
,是否可以发现它正在执行的主机的类型

差不多

ServiceHost host = new ServiceHost(typeof(MyContractImplementation));
Type serviceType = host.MagicCallHere();
Assert.True(typeof(MyContractImplementation) == serviceType);
这里有魔法吗


如果您可以避开反射,则会获得额外分数…

您可以检查描述服务类型属性:

var serviceType = host.Description.ServiceType
检查如下:

typeof(ServiceContract) == host.Description.ServiceType