begincsdn .NET 趴趴窝
[天行健,君子以自强不息]
[天道酬勤思]
posts - 37,  comments - 125,  trackbacks - 1

在面向AOP开发时,定义的是SingleCall,服务器激活模式。  
 
并且定义了interface供客户端和服务端同时使用,服务端实现该接口,  
客户端通过URL创建相应接口类型的实例代理。  
 
在访问时,程序可以正常访问,现希望通过:自定义上下文截获消息后,  
主要是对IMethodMessage类型消息处理。  
 
希望能获取消息访问的方法的所有属性(Attributes)  
无论使用:  
object  []  attrs  =  msg.MethodBase.GetCustomAttributes(true);  
还是使用  
object  []  attrs  =  msg.MethodBase.GetCustomAttributes(false);  
 
都只能获取接口上定义的属性,而不能获取到相应在服务器上实例的属性。  
 
现希望能获取实例类型相应方法上的属性。  
本来在CSDN上咨询过该问题,后来找到一个妥协的办法:

我实现的方法如下:

        public ServiceContextSink(IMessageSink nextSink)
        {
            WellKnownServiceTypeEntry[] wells;
            wells = System.Runtime.Remoting.RemotingConfiguration.GetRegisteredWellKnownServiceTypes();
            foreach (WellKnownServiceTypeEntry e in wells)
            {
                table["/"+e.ObjectUri] = Type.GetType(e.TypeName);
            }
            this.nextSink = nextSink;
        }

        private object[] GetCustomAttributes(string uri,IMethodMessage msg)
        {
            int index = uri.LastIndexOf('/');
            string url = uri.Substring(index, uri.Length - index);
            Type type = table[url] as Type;
            Type[] types = new Type[msg.ArgCount];
           
            index = 0;
            for (int i = 0 ; i < msg.ArgCount ; i++)
            {
                Type t = msg.Args[i].GetType();
                types[i] = t == null ? typeof(object) : t;
            }
            MethodInfo info = type.GetMethod(msg.MethodName, types);
            if (info == null)
                return new object[0];

            return info.GetCustomAttributes(false);
        }

posted on 2007-01-25 16:26 begincsdn 阅读(871) 评论(0)  编辑 收藏 所属分类: .net FrameworkRemoting

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2007-01-25 16:29 编辑过
"五向定位"职业成长路线公开课(上海、南京、大连)
Google站内搜索


相关链接:
 




我的MSN:
begincsdn@hotmail.com

<2007年1月>
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910

与我联系

搜索

 

常用链接

留言簿(3)

我参与的团队

随笔分类(34)

随笔档案(37)

文章分类(1)

积分与排名

  • 积分 - 39759
  • 排名 - 1090

最新评论

阅读排行榜

评论排行榜