`

HessianCSharp 1.3.3版本前使用泛型以及接口interface继承问题解决方案!!(实例代码)

 
阅读更多

相比 WebService Hessian 更简单、快捷。采用的是二进制 RPC 协议,因为采用的是二进制协议,所以它很适合于发送二进制数据。下面演示一个简单的 Hessian 示例程序。


知道Hessian 已经远超期待!

 Java、Flash、Python、C++、.NET C#、D、Erlang、PHP、Ruby,看看伟大的Hessian 当前所支持的语言吧!


HessianCSharp 1.3.3版本前使用泛型以及接口interface继承问题解决方案!!(实例代码) 其他废话不说啦...

--------------------------------------------------------------------------------------------------------------------------------------

web.config

 

<?xml version="1.0"?>
<configuration>
    <system.web>
        <authentication mode="Windows"/>
        <webServices>
            <protocols>
                <remove name="HttpPost"/>
                <remove name="HttpGet"/>
            </protocols>
        </webServices>
        <httpHandlers>
      <add verb="*" path="FilterService.hessian" type="App.Services.FilterService, Filter"/>
      <add verb="*" path="HttpService.hessian" type="App.Services.HttpService, Filter"/>
      <add verb="*" path="QueueService.hessian" type="App.Services.QueueService, Filter"/>
        </httpHandlers>
        <compilation debug="true">
        </compilation>
    </system.web>
    <startup><supportedRuntime version="v2.0.50727"/></startup>
    <system.codedom>
    </system.codedom>
    <system.webServer>
    </system.webServer>
</configuration>

-----------------------------------------------------------------------------

QueueService

 

public class QueueService : ServiceBase, IQueueService
    {
        string baseDataPath = @"d://queue//";
        public string Dequeue()
        {
            return GroupID;
        }
        public void Enqueue(string item)
        {

        }
        public void Load()
        {

        }

        public void Save()
        {

        }
       public  List<string> vv()
        {
            return new List<string>();
        }

-------------------------------------------------------------------------------------------------------------------------

public class ServiceBase : CHessianHandler
    {
        string id = "default";
        string groupId = "default";
       public string ID
        {
            set { id = value; }
            get { return id; }
        }
       public string GroupID
        {
            set { groupId = value; }
            get { return groupId; }
        }
    }

-------------------------------------------------------------------------------------------------------------------------------

 public interface IQueueService : IQueueService<string>
    {
       
    }
   public interface IQueueService<T>
   {
       string ID { set; get; }
       string GroupID { set; get; }
       string Dequeue();
       void Enqueue(T value);
       void Load();
       void Save();
       List<string> vv();
   }

------------------------------------------------------------------------------------------------------------------------

调试

 

 class Program
    {
        static void Main(string[] args)
        {
            CHessianProxyFactory f = new CHessianProxyFactory();
            f.IsOverloadEnabled = true;//
            string url="http://localhost:3263/";
            IQueueService service = f.Create(typeof(IQueueService), url + "QueueService.hessian") as IQueueService;

            url = "http://blog.csdn.net/zfrong";
            string data = "";

            List<string> v;
           
             data= service.Dequeue();
            v = service.vv();//


        }

以上调试结果   data返回null;v返回null;无法调用.....

 

问题原因 : 接口继承的情况下, proxyType是接口的话, proxyType.GetMethods();找不到接口继承的接口方法...


IQueueService service = f.Create(typeof(IQueueService), url + "QueueService.hessian") as IQueueService;

改成  

IQueueService<string> service = f.Create(typeof(IQueueService<string>), url + "QueueService.hessian") as IQueueService<string>;

以上调试结果   data返回"default";v返回 new实例;调用成功!!!!!!!!

--------------------------------------------------------------------------------------------------------

 

下面 看如何 解决....解决方案如下...... 修改源代码 中 CHessianProxyStandardImpl类

hessiancsharp.client
/// <summary>
    /// Proxy that works with .NET - Remote proxy framework
    /// </summary>
    public class CHessianProxyStandardImpl

-------------------------

添加 以下3个新方法 add new method;

 

/// <summary>
        /// 曾繁荣 zfrong2000@hotmail.com blog:http://blog.csdn.net/zfrong
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        MethodInfo[] GetTypeMethods(Type t)
        {
            if (t.IsInterface)
            {
               System.Collections.Generic.List<MethodInfo> mColl=new System.Collections.Generic.List<MethodInfo>();
               GetInterfaceMethods(t,mColl);
               return mColl.ToArray();//
            }
            else
                return t.GetMethods();//
        }
        /// <summary>
        /// 曾繁荣 zfrong2000@hotmail.com blog:http://blog.csdn.net/zfrong
        /// </summary>
        /// <param name="type"></param>
        /// <param name="mColl"></param>
        void GetInterfaceMethods(Type type,System.Collections.Generic.List<MethodInfo> mColl)
        {
            if (type.IsInterface)
            {

               mColl.AddRange(t.GetMethods());//
                Type[] ts = type.GetInterfaces();
                foreach (Type t in ts)
                {
                    GetInterfaceMethods(t, mColl);//
                }
            }
        }

 /// <summary>
        ///  /// 曾繁荣 zfrong2000@hotmail.com blog:http://blog.csdn.net/zfrong
        /// </summary>
        /// <param name="methodMessage"></param>
        /// <returns></returns>
        MethodInfo GetMethodInfoFor(IMethodCallMessage methodMessage)
        {
            foreach (MethodInfo m in this.m_methods)
            {
                if (m.Name.Equals(methodMessage.MethodName))
                    return m;
            }
            return null;
        }

...以上3方法辅助接口找到所有继承的接口的接口方法c# interface

 

然后-------修改   源代码中   ........

public CHessianProxyStandardImpl(Type proxyType,CHessianProxyFactory hessianProxyFactory, Uri uri) : base(typeof(IHessianProxyStandard))
        {
            this.m_proxyType = proxyType;   
            this.m_methodCaller = new CHessianMethodCaller(hessianProxyFactory,uri);
            //this.m_methods = proxyType.GetMethods();
            this.m_methods =GetTypeMethods(proxyType) ;//zfrong

//问题原因 : 接口继承的情况下, proxyType是接口的话, proxyType.GetMethods();找不 到接口继承的接口方法...

        }

        public CHessianProxyStandardImpl(Type proxyType, CHessianProxyFactory hessianProxyFactory, Uri uri, string username, string password)
            : base(typeof(IHessianProxyStandard))
        {
            this.m_proxyType = proxyType;
            this.m_methodCaller = new CHessianMethodCaller(hessianProxyFactory, uri, username, password);
            //this.m_methods = proxyType.GetMethods();
            this.m_methods = GetTypeMethods(proxyType);//zfr
ong
        }

 

 private MethodInfo GetMethodInfoForMethodBase(IMethodCallMessage methodMessage)
        {
            if (IsMethodNameUnique(methodMessage.MethodName))
            {  
                if(this.m_proxyType.IsInterface)
                     return GetMethodInfoFor(methodMessage);

                return this.m_proxyType.GetMethod(methodMessage.MethodName);
            }
            else
            {
                if (this.m_proxyType.IsInterface)
                    return GetMethodInfoFor(methodMessage);

                return this.m_proxyType.GetMethod(methodMessage.MethodName, CHessianMethodCaller.GetArgTypes(methodMessage.Args));
            }
        }

 
分享到:
评论

相关推荐

    RFID_Tools_1.3.3

    功能没有阉割的老版本

    commons-fileupload-1.3.3&commons-fileupload-1.3.3架包和代码.rar

    commons-fileupload-1.3.3 commons-io-2.2 mysql-connector-java-5.1.37-bin druid-1.0.9

    GO工具and编译器 1.3.3版本2

    GO工具and编译器 1.3.3版本 官方原版下载 原滋原味

    GO工具and编译器 1.3.3版本1

    GO工具and编译器 1.3.3版本 官方原版下载 原滋原味

    GO工具and编译器 1.3.3版本3

    GO工具and编译器 1.3.3版本 官方原版下载 原滋原味 注意:最后一个分卷扣2分

    Odyssey-1.3.3免墙下载

    IOS14越狱,Odyssey-1.3.3 最新版 免墙下载 稳定不重启

    jasperreports-1.3.3与iReport1.3.3初级使用

    NULL 博文链接:https://wallboy.iteye.com/blog/468546

    config-1.3.3-API文档-中文版.zip

    赠送jar包:config-1.3.3.jar; 赠送原API文档:config-1.3.3-javadoc.jar; 赠送源代码:config-1.3.3-sources.jar; 赠送Maven依赖信息文件:config-1.3.3.pom; 包含翻译后的API文档:config-1.3.3-javadoc-API...

    领域驱动设计C# 2008实现问题.设计.解决方案

    1.3 解决方案 1.3.1 满足可靠性、可得性、伸缩性、离线可得和附加客户设备支持需求 1.3.2 满足可维护性需求 1.3.3 满足富客户应用功能需求 1.3.4 满足web访问需求 1.3.5 满足智能安装和自动更新功能需求 1.4 ...

    commons-fileupload-1.3.3-API文档-中文版.zip

    赠送jar包:commons-fileupload-1.3.3.jar; 赠送原API文档:commons-fileupload-1.3.3-javadoc.jar; 赠送源代码:commons-fileupload-1.3.3-sources.jar; 赠送Maven依赖信息文件:commons-fileupload-1.3.3.pom;...

    IEC61850-1.3.3开源代码说明文档

    libiec61850 1.3.3的库说明文档,自己整理了为chm,半离线状态,里面算是连接吧,看着有需要的就下载吧。官网也有的

    IOT替换工具V1.3.3.zip

    IOT替换工具V1.3.3.zip \IOT替换工具V1.3.3.zip \IOT替换工具V1.3.3.zip \IOT替换工具V1.3.3.zip \IOT替换工具V1.3.3.zip \IOT替换工具V1.3.3.zip \IOT替换工具V1.3.3.zip \IOT替换工具V1.3.3.zip \IOT替换工具V...

    jQuery EasyUI 1.3.3 源码

    jQuery EasyUI 1.3.3 未混淆的源代码。下载阅读后,可以深入了解实现过程,以及更容易扩展实现。

    classmate-1.3.3-API文档-中文版.zip

    赠送jar包:classmate-1.3.3.jar; 赠送原API文档:classmate-1.3.3-javadoc.jar; 赠送源代码:classmate-1.3.3-sources.jar; 赠送Maven依赖信息文件:classmate-1.3.3.pom; 包含翻译后的API文档:classmate-...

    MyBatis_Generator_1.3.3

    通告 MyBatis的Generator现在需要JRE 1.6或更高版本 增强功能 改变了注解提供Generator使用新的SQL生成器类从MyBatis的3.2。...问题#10 - EqualsHashCodePlugin现在使用数组属性java.util.Arrays中的方法。

    tui-editor1.3.3

    tui-editor1.3.3/tui-editor/tui-editor死活下载不了

    精通CSS高级Web标准解决方案-包含源码(高清PDF中文版)

    本书将最有用的CSS技术汇总在一起,在介绍基本的CSS概念和最佳实践之后,讨论了核心的CSS技术,例如图像、链接、列表操纵、表单设计、数据表格设计以及纯CSS布局。每一章内容由浅入深,直到建立比较复杂的示例。之后...

    百度魔拍 v1.3.3

    版本:1.3.3 软件语言:中文 软件类别:特效相机 软件大小:40.19 MB 适用固件:2.2及更高固件 内置广告:没有广告 适用平台:Android 百度魔拍--智能让美更简单 不断更换相机app,只为拍摄一张更美的照片,却总是...

    commons-fileupload-1.3.3.zip

    Apache Struts2 Commons FileUpload反序列化远程代码执行漏洞安全公告 安全公告编号:CNTA-2018-... 目前,Apache公司已发布了新版本(Struts 2.5.12及以上版本,包括Commons FileUpload库的修补版本1.3.3)修复了该漏洞

    下载王APP 最新v1.3.3版本 包含短视频去水印、4K/1080P高清视频下载等功能

    这个是安卓手机上的下载工具「下载王」APP的最新v.1.3.3版本,新增双11领红包优惠券功能,给好友发福利码,后台下载列表新增批量删掉等功能。

Global site tag (gtag.js) - Google Analytics