C# 如何获取当前端点契约的类型?
我有一个消息检查器,试图在其中获取当前端点的契约类型。我想考虑类型,但C# 如何获取当前端点契约的类型?,c#,wcf,C#,Wcf,我有一个消息检查器,试图在其中获取当前端点的契约类型。我想考虑类型,但GetType返回null var contractType = Type.GetType(OperationContext.Current.EndpointDispatcher.ContractName); if (contractType != null) { foreach (var member in contractType.GetMembers()) { //do stuff
GetType
返回null
var contractType = Type.GetType(OperationContext.Current.EndpointDispatcher.ContractName);
if (contractType != null)
{
foreach (var member in contractType.GetMembers())
{
//do stuff
}
}
我猜是因为
OperationContext.Current.EndpointDispatcher.ContractName
保存接口的名称,而不是完全限定的类型名称。它无法获取类型。我的配置具有完全限定的类型名,因此我不确定.NET为什么要这样做。是否有其他方法可以获得它?您可以通过以下方式找到正确的类型:
OperationContext.Current.EndpointDispatcher.DispatchRuntime.Type
见MSDN:
这是服务类型,但我需要合同类型。不过,这让我朝着正确的方向前进。我可以通过这样做得到-var im=OperationContext.Current.EndpointDispatcher.DispatchRuntime.Type.GetInterfaceMap(OperationContext.Current.EndpointDispatcher.DispatchRuntime.Type.GetInterface(OperationContext.Current.EndpointDispatcher.ContractName));然后我可以从im.InterfaceMethods中获得方法。谢谢{