最新下载
热门教程
- 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)的对象。
相关文章
- 豆包AI免费在线使用-豆包AI官网网页版直达入口 12-20
- libvio官网在线追剧入口-libvio免费高清追剧网页版官网直达 12-20
- 林东江珊番茄小说畅读入口-林东江珊番茄小说爆款作品一键直达入口 12-20
- 原神玉衡杯官网入口2026-最新原神玉衡杯数据库网址速览 12-20
- 阿里旺旺网页版入口-阿里旺旺Web版官网登录入口 12-20
- 暴风影音手机版官网直达-暴风影音官网手机版下载 12-20