我想列出来自具有"OperationContractAttribute“属性的WCF服务的所有方法。
为此,我使用以下代码:
var service = assembly.GetType(typeName);
if (service == null)
return webMethodsInfo;
var methodsInfo = service.GetMethods();
webMethods = methodsInfo.Where(method => method.GetCustomAttributes
(typeof(OperationContractAttribute), true).Any()).ToList();因此,OperationContractAttribute是在接口(IClassA)中指定的,当我尝试在ClassA类中搜索此方法属性时,它无法找到它,但是我为方法GetCustomAttributes指定了标志true,用于搜索祖先
发布于 2013-01-30 18:41:13
这个就行了
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;
}
}发布于 2013-01-30 18:58:26
webMethods = service.GetInterface(serviceContract).GetMethods().Where(
method => method.GetCustomAttributes
(typeof(OperationContractAttribute)).Any())
.ToList();https://stackoverflow.com/questions/14600627
复制相似问题