0

属性「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のフラグを指定しました

4

2 に答える 2

1

これでうまくいく

 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-30T10:41:12.827 に答える
0
webMethods = service.GetInterface(serviceContract).GetMethods().Where(
    method => method.GetCustomAttributes
      (typeof(OperationContractAttribute)).Any())
      .ToList();
于 2013-01-30T10:58:25.603 に答える