zoukankan      html  css  js  c++  java
  • Remoting压缩信道的编程配置方式

    在网上看到(包括MSDN中)关于自定义压缩信道的配置方式都是使用*.config配置文件的方式,可以是我的框架中是自定义的配置文件,编程实现Remoting的配置,要编程配置自定义信道方法如下:

    服务端:

                    //建立一个端口键值对。名称,端口号。
                    IDictionary props = new Hashtable();
                    props[
    "name"= serviceName;
                    props[
    "port"= channelPort;        

                    
    //为使用 压缩接收器 的服务器格式化程序信道接收器提供程序提供实现。
                    JCsoft.Common.Remoting.Channels.CompressionServerFormatterSinkProvider serverSinkProvider = new JCsoft.Common.Remoting.Channels.CompressionServerFormatterSinkProvider(compressionLevel);
                    
                    
    //注册信道。
                    switch(channelType)
                    
    {
                        
    case ChannelType.TCP:
                        
    {
                            serverSinkProvider.Next 
    = new System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider();
                            ChannelServices.RegisterChannel(
    new TcpServerChannel(props, serverSinkProvider));
                            
    break;
                        }

                        
    case ChannelType.HTTP:
                        
    {
                            serverSinkProvider.Next 
    = new System.Runtime.Remoting.Channels.SoapServerFormatterSinkProvider();
                            ChannelServices.RegisterChannel(
    new HttpServerChannel(props, serverSinkProvider));
                            
    break;
                        }

                    }


                    
    //注册服务类型。
                    switch(objectMode)
                    
    {
                        
    case ObjectMode.Singleton:
                        
    {
                            RemotingConfiguration.RegisterWellKnownServiceType(serviceType, serviceName, WellKnownObjectMode.Singleton);
                            
    break;
                        }

                        
    case ObjectMode.SingleCall:
                        
    {
                            RemotingConfiguration.RegisterWellKnownServiceType(serviceType, serviceName, WellKnownObjectMode.SingleCall);
                            
    break;
                        }

                    }
                
                    
    return true;


    客户端:
                object service = null;
                
    string machine = "localhost";
                
    string connectionString = string.Empty;

                
    //为使用 压缩接收器 的服务器格式化程序信道接收器提供程序提供实现。
                JCsoft.Common.Remoting.Channels.CompressionClientFormatterSinkProvider clientSinkProvider = new JCsoft.Common.Remoting.Channels.CompressionClientFormatterSinkProvider(compressionLevel);
    //            JCsoft.Common.Remoting.Channels.CompressionClientFormatterSink clientSink = new JCsoft.Common.Remoting.Channels.CompressionClientFormatterSink(compressionLevel);
                    
                
    //注册信道。
                switch(channelType)
                
    {
                    
    case ChannelType.TCP:
                    
    {
                        System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider firstClientSinkProvider 
    = new System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider();
                        firstClientSinkProvider.Next 
    = clientSinkProvider;
                        IDictionary props 
    = new Hashtable();
    //                    props["name"] = "TcpClientChannel";
                        
    //props["priority"] = 100;        
                        ChannelServices.RegisterChannel(new TcpClientChannel(props, firstClientSinkProvider));
    //                    ChannelServices.RegisterChannel(new BinaryClientFormatterSink(clientSink));
                        break;
                    }

                    
    case ChannelType.HTTP:
                    
    {
                        System.Runtime.Remoting.Channels.SoapClientFormatterSinkProvider firstClientSinkProvider 
    = new System.Runtime.Remoting.Channels.SoapClientFormatterSinkProvider();
                        firstClientSinkProvider.Next 
    = clientSinkProvider;
                        IDictionary props 
    = new Hashtable();
    //                    props["name"] = "HttpClientChannel";
                        
    //props["priority"] = 100;        
                        ChannelServices.RegisterChannel(new HttpClientChannel(props, firstClientSinkProvider));
    //                    ChannelServices.RegisterChannel(new SoapClientFormatterSink(clientSink));
                        break;
                    }

                }


                
    switch(channelType)
                
    {
                    
    case ChannelType.TCP:
                    
    {
                        connectionString 
    = string.Format("tcp://{0}:{1}/{2}", machine, channelPort, serviceName);
                        
    break;
                    }

                    
    case ChannelType.HTTP:
                    
    {
                        connectionString 
    = string.Format("http://{0}:{1}/{2}", machine, channelPort, serviceName);
                        
    break;
                    }

                }

                
    try
                
    {
                    service 
    = Activator.GetObject(serviceType, connectionString);
                }

                
    catch(Exception ex)
                
    {
                    
    // 处理异常。
                    ExceptionManager.Publish(ex);
                }

    代码中部分注释掉的是错误的。

    如何实现压缩信道可以参见博客园-Zendy实现一个压缩Remoting传输数据的Sink:CompressionSink 的一篇文件http://www.cnblogs.com/caomao/archive/2005/07/29/202942.aspx,当然也可以自已看MSDN来学习

  • 相关阅读:
    如何判断两个IP是否在同一网段
    http://blog.csdn.net/a9529lty/article/details/6454156
    http://blog.csdn.net/a9529lty/article/details/6454145
    tomcat下配置https环境(windows环境)
    hosts文件配置及主要作用
    函数y=sin(1/x)曲线
    求证:a^4+b^4 ≧a^3*b+a*b^3
    三种双二次曲线
    已知m和n是两个整数,并且m^2+mn+n^2能被9整除,试证m,n都能被3整除。
    x为正变数,求y=x^3/(x^4+4)的最大值
  • 原文地址:https://www.cnblogs.com/zhongzf/p/211252.html
Copyright © 2011-2022 走看看