此处下载源代码(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);
}
}
}
}
好了,下面看看结果:
 

注:以上所有操作均在同一台电脑,并且在同一个解决方案执行。

接下来会跟大家分享Remoting在局域网里的使用

C# Remoting 简单实现的更多相关文章

  1. Remoting简单实践

    一句话概括 remoting是微软的一种实现在不同的.net应用程序中进行分布式通信的技术 重要概念 原理大致是首先客户端通过remoting通道来获取服务器对象代理,通过序列化与反序列方式实现数据交 ...

  2. salesforce 零基础学习(二十八)使用ajax方式实现联动

    之前的一篇介绍过关于salesforce手动配置关联关系实现PickList的联动效果,但是现实的开发中,很多数据不是定死的,应该通过ajax来动态获取,本篇讲述通过JavaScript Remoti ...

  3. salesforce

    salesforce&apex salesforce开发的小心得 salesforce零基础学习(七十七)队列的实现以及应用 摘要: 队列和栈简单的区别为栈是后进先出,队列是先进先出.队列也是 ...

  4. .Net中Remoting通信机制简单实例

    .Net中Remoting通信机制 前言: 本程序例子实现一个简单的Remoting通信案例 本程序采用语言:c# 编译工具:vs2013工程文件 编译环境:.net 4.0 程序模块: Test测试 ...

  5. 【Remoting】.Net remoting方法实现简单的在线升级(上篇:更新文件)

    一.前言:       最近做一个简单的在线升级Demo,使用了微软较早的.Net Remoting技术来练手. 简单的思路就是在服务器配置一个Remoting对象,然后在客户端来执行Remoting ...

  6. C# Remoting的一个简单例子

    .Net对于远程调用提供了两种方法:Remoting和WebService.WebService现在是如火如荼,特别是有一种比较流行的架构:Winform+WebService(Java..Net), ...

  7. NET Remoting 最简单示例

    NET Remoting 最简单示例 2014-01-21 15:29 10492人阅读 评论(4) 收藏 举报  分类: .NET(6)  版权声明:本文为博主原创文章,未经博主允许不得转载. 学习 ...

  8. 简单学会.net remoting

    简介 •.net remoting是.net在RPC分布式应用的技术.首先,客户端通过 remoting访问通道以获得服务端对象,再通过代理解析为客户端对象,通过通道来实现远程对象的调用. 原理 •远 ...

  9. 【Remoting】.Net remoting方法实现简单的在线升级(下篇:重启exe)

    一.前言      上篇运用了.Net Remoting技术解决了本地与服务器版本对比,并下载更新包的过程. 本篇主要是应用Process,来实现重启程序的过程. 情景假设:       Revit2 ...

随机推荐

  1. 简学Python第五章__模块介绍,常用内置模块

    Python第五章__模块介绍,常用内置模块 欢迎加入Linux_Python学习群  群号:478616847 目录: 模块与导入介绍 包的介绍 time &datetime模块 rando ...

  2. ajax设置Access-Control-Allow-Origin实现跨域访问

    ajax跨域访问 1.jsonp方法,jsonp方法是一种非官方方法,这种方法只支持GET方式, 不如POST方式安全.(即使使用jquery的jsonp方法,type设为POST, 也会自动变为GE ...

  3. (python)循环中动态产生变量

    >>> for i in xrange(5): exec 'a'+str(i)+' = '+str(i)+'' >>> a0 0 >>> a1 1 ...

  4. mysql与mongodb命令对比

    连接:mysql: mysql -h localhost -u username -pmongodb:con = pymongo.Connection(‘localhost’,27017)显示数据库m ...

  5. 使用npm安装github仓库中的代码

    我们在使用npm下载包的时候,一般是下载在npm官网发布过的.可以指定版本,指定依赖等等. 但是,对于一个团队或公司,需要从自己的工作账号拉取代码,npm是直接支持从git仓库安装的. 最近遇到的一个 ...

  6. hdu3157有源汇上下界最小流

    题意:有源汇上下界最小流裸题,主要就是输入要用字符串的问题 #include<bits/stdc++.h> #define fi first #define se second #defi ...

  7. splunk的统计分析功能——特定字段的统计功能包括取值分布(+topK,min/max/平均值)

    特定字段的统计功能——取值分布,topK,min/max/平均值 例如: date_second 60 值, 100% 的事件 时段平均值 时段最大值 时段最小值 上限值 时段上限值 罕见值 具有此字 ...

  8. 基于鸿洋博客自定于View实现的android音量调节控件

    1.在values建立attrs.xml,写出你需要的属性: <?xml version="1.0" encoding="utf-8"?> < ...

  9. Solr单机版安装

    感谢 shliuzw 的分享,原文地址http://blog.csdn.net/liuzhenwen/article/details/4060922 感谢 upxiaofeng 的分享,原文地址 ht ...

  10. 详解linux互斥锁 pthread_mutex和条件变量pthread_cond

    [cpp] view plaincopy ============================================================= int pthread_creat ...