正在使用WPF中的WCF服务,我想列出服务中的所有方法名称。
我尝试了两种解决方案:1。
MethodInfo[] methods = typeof(TypeOfTheService).GetMethods();
foreach (var method in methods)
{
string methodName = method.Name;
}
它列出了所有功能,但还包括其他一些功能,例如“ to string”,“ open”,“ abort”等。
2。
MethodInfo[] methods = typeof(ITimeService).GetMethods();
foreach (var method in methods)
{
if (((System.Attribute)(method.GetCustomAttributes(true)[0])).TypeId.ToString() == "System.ServiceModel.OperationContractAttribute")
{
string methodName = method.Name;
}
}
它最终会显示一个错误,显示“索引超出范围”。
您可以在服务合同中搜索方法,即interface,它将不包含任何方法,例如ToString()
:
var contractMethods = typeof(ITimeService).GetMethods(); // not TimeService
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句