最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
构建基本的.NET Remoting应用程序
时间:2022-07-02 10:53:05 编辑:袖梨 来源:一聚教程网
构建一个使用.NET远程处理框架来进行应用域(application domain )间通信的应用程序很简单。你必须实现远程类型(remotable type)、用于监听请求的服务应用域和客户应用域。同时,你必须为每个应用域配置远程处理系统(remoting system ),以便可以使用远程激活( remote activation )来激活远程类型。
一、创建远程类型(remotable type):
为了使其它应用域中的对象可以使用你的类实例,你的类必须从System.MarshalByRefObject类进行派生。下面的代码说明如何创建远程类:
[Visual Basic]
' RemotableType.vb
Imports System
Public Class RemotableType
Inherits MarshalByRefObject
Private _internalString As String = "This is the RemotableType."
Public Function StringMethod() As String
Return _internalString
End Function 'StringMethod
End Class 'RemotableType
[C#]
// RemotableType.cs
using System;
public class RemotableType : MarshalByRefObject{
private string _internalString = "This is the RemotableType.";
public string StringMethod(){
return _internalString;
}
}
为了使用.NET Framework SDK附带的命令行工具来将上例中的类编译成为库文件,只要将它保存为RemotableType.language-extension(此处language-extension是你所使用的语言,比如cs、vb)。编译时使用如下命令:
[Visual Basic]
vbc /t:library RemotableType.vb
[C#]
csc /noconfig /t:library RemotableType.cs
二、创建服务应用(host application):
要在不同地应用域(application domain)中创建远程对象的实例,你必须创建服务应用来完成两个任务:
(1)选择并且注册一个通道(channel)。该通道是一个处理网络协议和串行格式化(serialization format)的对象。
一、创建远程类型(remotable type):
为了使其它应用域中的对象可以使用你的类实例,你的类必须从System.MarshalByRefObject类进行派生。下面的代码说明如何创建远程类:
[Visual Basic]
' RemotableType.vb
Imports System
Public Class RemotableType
Inherits MarshalByRefObject
Private _internalString As String = "This is the RemotableType."
Public Function StringMethod() As String
Return _internalString
End Function 'StringMethod
End Class 'RemotableType
[C#]
// RemotableType.cs
using System;
public class RemotableType : MarshalByRefObject{
private string _internalString = "This is the RemotableType.";
public string StringMethod(){
return _internalString;
}
}
为了使用.NET Framework SDK附带的命令行工具来将上例中的类编译成为库文件,只要将它保存为RemotableType.language-extension(此处language-extension是你所使用的语言,比如cs、vb)。编译时使用如下命令:
[Visual Basic]
vbc /t:library RemotableType.vb
[C#]
csc /noconfig /t:library RemotableType.cs
二、创建服务应用(host application):
要在不同地应用域(application domain)中创建远程对象的实例,你必须创建服务应用来完成两个任务:
(1)选择并且注册一个通道(channel)。该通道是一个处理网络协议和串行格式化(serialization format)的对象。
相关文章
- 死亡搁浅2NPC升星技巧分享 07-02
- 卡普空制作人亲自解释为什么里昂不是《生化危机9:安魂曲》主角! 07-02
- 教你用PS与LR打造日系清新男神艺术照 07-02
- 黑暗之魂2鼠王的试炼怎么打 07-02
- 资讯:三大交易所app下载 全球前三大加密货币交易所 07-02
- 美国运通美联储更新引发瑞波整合热议 07-02