首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从WCF获取ServiceContract方法

从WCF获取ServiceContract方法
EN

Stack Overflow用户
提问于 2013-01-30 17:34:30
回答 2查看 779关注 0票数 0

我想列出来自具有"OperationContractAttribute“属性的WCF服务的所有方法。

为此,我使用以下代码:

代码语言:javascript
复制
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,用于搜索祖先

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-30 18:41:13

这个就行了

代码语言:javascript
复制
 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;
                }
            }
票数 1
EN

Stack Overflow用户

发布于 2013-01-30 18:58:26

代码语言:javascript
复制
webMethods = service.GetInterface(serviceContract).GetMethods().Where(
    method => method.GetCustomAttributes
      (typeof(OperationContractAttribute)).Any())
      .ToList();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14600627

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档