C# Remoting 简单实现
此处下载源代码(VS2010编译通过)
http://files.cnblogs.com/files/qqhfeng/%E8%BF%9C%E7%A8%8B%E8%B0%83%E7%94%A8%E6%B5%8B%E8%AF%952.rar

RemotingModel: Talker.cs using System;
using System.Collections.Generic;
using System.Text; namespace RemotingModel
{
/// <summary>
///
/// </summary>
public class Talker:MarshalByRefObject
{
/// <summary>
/// 说话
/// </summary>
/// <param name="word"></param>
public void Talk(string word)
{
System.Console.WriteLine(word);
}
}
} 服务器端:是一个控制台,首先要添加对System.Runtime.Remoting的引用,然后添加对RemotingModel的引用 using System;
using System.Collections.Generic;
using System.Text; using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp; using RemotingModel; namespace RemotingServer
{
class Program
{
static void Main(string[] args)
{
//注册通道
TcpServerChannel channel = new TcpServerChannel("TalkChannel", ); //端口随便取
ChannelServices.RegisterChannel(channel, true); //注册远程对象
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(Talker),
"Talker", WellKnownObjectMode.SingleCall); Console.ReadLine();
}
}
} 客服端:窗体:两个textBox,一个button,设置textBox为多行。上面的textBox为:txtContent,下面的为:txtWord

添加引用(添加方法同上) using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp; using RemotingModel;
namespace RemotingClient
{
public partial class Form1 : Form
{
private Talker _talk = null;
public Form1()
{
InitializeComponent();
} private void btnSend_Click(object sender, EventArgs e)
{
try
{
//操作远程对象
_talk.Talk(txtWord.Text.Trim());
txtContent.Text = "发送成功" + txtWord.Text.Trim();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
} private void Form1_Load(object sender, EventArgs e)
{
try {
//注册通道
TcpClientChannel channel = new TcpClientChannel();
ChannelServices.RegisterChannel(channel, true); //获取远程对象
_talk=(Talker) Activator.GetObject(typeof(Talker),"TCP://localhost:8090/Talker");
}
catch(Exception ex){
MessageBox.Show(ex.Message);
}
}
}
}
好了,下面看看结果:


注:以上所有操作均在同一台电脑,并且在同一个解决方案执行。
C# Remoting 简单实现的更多相关文章
- Remoting简单实践
一句话概括 remoting是微软的一种实现在不同的.net应用程序中进行分布式通信的技术 重要概念 原理大致是首先客户端通过remoting通道来获取服务器对象代理,通过序列化与反序列方式实现数据交 ...
- salesforce 零基础学习(二十八)使用ajax方式实现联动
之前的一篇介绍过关于salesforce手动配置关联关系实现PickList的联动效果,但是现实的开发中,很多数据不是定死的,应该通过ajax来动态获取,本篇讲述通过JavaScript Remoti ...
- salesforce
salesforce&apex salesforce开发的小心得 salesforce零基础学习(七十七)队列的实现以及应用 摘要: 队列和栈简单的区别为栈是后进先出,队列是先进先出.队列也是 ...
- .Net中Remoting通信机制简单实例
.Net中Remoting通信机制 前言: 本程序例子实现一个简单的Remoting通信案例 本程序采用语言:c# 编译工具:vs2013工程文件 编译环境:.net 4.0 程序模块: Test测试 ...
- 【Remoting】.Net remoting方法实现简单的在线升级(上篇:更新文件)
一.前言: 最近做一个简单的在线升级Demo,使用了微软较早的.Net Remoting技术来练手. 简单的思路就是在服务器配置一个Remoting对象,然后在客户端来执行Remoting ...
- C# Remoting的一个简单例子
.Net对于远程调用提供了两种方法:Remoting和WebService.WebService现在是如火如荼,特别是有一种比较流行的架构:Winform+WebService(Java..Net), ...
- NET Remoting 最简单示例
NET Remoting 最简单示例 2014-01-21 15:29 10492人阅读 评论(4) 收藏 举报 分类: .NET(6) 版权声明:本文为博主原创文章,未经博主允许不得转载. 学习 ...
- 简单学会.net remoting
简介 •.net remoting是.net在RPC分布式应用的技术.首先,客户端通过 remoting访问通道以获得服务端对象,再通过代理解析为客户端对象,通过通道来实现远程对象的调用. 原理 •远 ...
- 【Remoting】.Net remoting方法实现简单的在线升级(下篇:重启exe)
一.前言 上篇运用了.Net Remoting技术解决了本地与服务器版本对比,并下载更新包的过程. 本篇主要是应用Process,来实现重启程序的过程. 情景假设: Revit2 ...
随机推荐
- 使用Properties读写属性文件
import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Properties; /*Prop ...
- sshfs的挂载与卸载
在CentOS中 sshfs的使用依赖EPEL(只安装sshfs不会出错,但是却无法使用) 挂载 安装EPEL rpm -i https://dl.fedoraproject.org/pub/epel ...
- monkey参数应用
1.指定seed值 adb shell monkey -v -p package -s 100 100 2.touch事件(参数后都跟百分比) 3.设定动作百分比 4.轨迹球 5.基本导航事件 输入 ...
- The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files
要解决的话,方法有两个 1)可以选用较低版本的sdk,比如我就用回1.6版本的sdk window->preferences->Java->Installed JREs->Ad ...
- poj2135最小费用流
裸题,就是存个模板 最小费用流是用spfa求解的,目的是方便求解负环,spfa类似于最大流中的bfs过程 #include<map> #include<set> #includ ...
- mysql ORM框架及SQLAlchemy
一 介绍 SQLAlchemy是Python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用关系对象映射进行数据库操作,简言之便是:将对象转换成SQL,然后使用数据API执行SQL并获取 ...
- 剑指offer--16.数组中重复的数字
时间限制:1秒 空间限制:32768K 热度指数:198342 本题知识点: 数组 题目描述 在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复 ...
- nyoj-1016-德莱联盟(向量叉乘判断线段相交)
叉乘的坐标表示: A(X1,Y1), B(X2, Y2), C(XC,YC), D(XD, YD);AB = (X2-X1, Y2-Y1);CD = (XD-XC, YD-YC); 向量AB,CD的叉 ...
- git教程3-添加远程库与从远程库拷贝
一.添加到github 1.github上创建新的库learngit.git 2.git remote add origin git@github.com:moisiet/learngit.git ...
- 康托展开与逆康托展开模板(O(n^2)/O(nlogn))
O(n2)方法: namespace Cantor { ; int fac[N]; void init() { fac[]=; ; i<N; ++i)fac[i]=fac[i-]*i; } in ...