zoukankan      html  css  js  c++  java
  • 【.NetRemoting-3】2015.09.18

    【Remoting程序的基本实现】

    【一】服务程序集
    【1】服务对象必须要求继承【MBR,MarshalByRefObject】

    【二】服务端应用程序
    【1】注册通道
    【两种类型的通道】
    【A】发送请求的通道,要求实现IChannelSender 接口
    【B】接受请求的通道,要求实现IChannelReceiver 接口
    【.Net提供的内置通道】==>均实现了IChannelSender,IChannelReceiver,IChannel
    【HttpChannel】
    ==>可实现跨防火墙
    ==>【消息】通过【SOAP】格式化
    【TcpChannel】
    ==>无法跨防火墙
    ==>【消息】通过【二进制】格式化
    【IcpChannel】
    ==>不能跨计算机,只能在同一台计算机内跨线程访问。
    ==>底层基于【命名管道,Named Pipe】

    【代码实现】
    【A】实例化Channel对象
    ==>两种构造Channel对象的方法
    【B】使用ChannelServices.RegisterChannel(channelobj,bool)注册通道

    【2】注册类型==>告知客户端,宿主应用程序域中哪些对象是可以被客户端访问到的
    【服务对象的三种激活方式】
    【1】客户端激活
    【2】服务端激活Singleton【Server activated Singleton】
    【3】服务端激活SingleCall【Server activated SingleCall】

    【代码实现】
    ==>使用RemotingConfiguration.RegisterActivatedServiceType(type)【客户端激活】方法
    ==>使用RemotingConfiguration.RegisterWellKnowServiceType(type,"objUri",activatType)【服务端激活方式】

    【3】对象位置
    客户端如何知道对象位置?==>URL
    【RemotingConfiguration.ApplicationName】属性
    【URL形式】
    【Service Activated】
    ==> protocal://hsotadress:port/ApplicationName/ObjectUrl
    【Client Activated Object】
    ==> protocal://hsotadress:port
    ==> protocal://hsotadress:port/ApplicationName

    【三】客户端程序==>Only One Task
    ===>获取远程对象,调用远程对象方法。
    【步骤】
    【A】注册类型==>告知.Net该对象应该是在服务端注册的,而非在本地
    ==>客户端类型注册与服务端类型注册的方法类似【使用RemotingConfiguration】
    ==>使用RemotingConfiguration.RegisterActivatedClientType(type,uri)【客户端激活】方法
    ==>使用RemotingConfiguration.RegisterWellKnowClientType(type,"uri")【服务端激活方式】

    【B】new操作符创建对象

    【2】其他创建远程对象的方法
    ==>【RemotingServices.Connect()】==>简单,较为常用,只能调用无参构造函数,获取对象的同时创建代理
    ==>【Activator.GetObject()】==>简单,较为常用,只能调用无参构造函数,获取对象的同时创建代理
    ==>【Activator.CreateInstance()】==>可调用有参构造函数,但只能创建客户激活对象。

  • 相关阅读:
    vector、list、deque三者比较
    python多线程
    爬虫入门之线程进程协程抓取方法(八)
    爬虫之绘图matplotlib与词云(七)
    python字符串反转 高阶函数 @property与sorted(八)
    爬虫入门之Requests模块学习(四)
    爬虫入门之handler与opener(三)
    mongodb/python3.6/mysql的安装
    nginx配置+uwsgi+负载均衡配置
    [JLOI2016] 成绩比较
  • 原文地址:https://www.cnblogs.com/bea084100123/p/4822540.html
Copyright © 2011-2022 走看看