此处下载源代码(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. vc 改变控制台字符颜色

    #include <Windows.h> #include <stdio.h> #include <iostream> using namespace std; i ...

  2. idel 中 生成 jar包 和项目中自己需要的包

    一.首先在自己的项目中创建一个类类中创建一个构造方法构造方法中传入一个字符串参数(这个字符串参数是为了传入路径) 在方法体内通过file类创建文件夹(换而言之就是项目中的包) 二 .就是对这个项目中的 ...

  3. Http协议与生命周期

    一.Http知识:    1.基于socket        浏览器(格式一)        web服务器(格式一)        MYSQL客户端(格式二)        MYSQL服务端(格式三) ...

  4. spring: 在Spring应用中使用JDBC(使用profiles选择数据源/使用基于JDBC驱动的数据源)

    在实际开发过程中有很多持久化技术可供选择:Hibernate.iBATIS和JPA等.尽管如此,还是有很多应用使用古老的方法即JDBC技术,来访问数据库. 使用JDBC技术不需要开发人员学习新的框架, ...

  5. 论文笔记 — L2-Net: Deep Learning of Discriminative Patch Descriptor in Euclidean Space

    论文: 本文主要贡献: 1.提出了一种新的采样策略,使网络在少数的epoch迭代中,接触百万量级的训练样本: 2.基于局部图像块匹配问题,强调度量描述子的相对距离: 3.在中间特征图上加入额外的监督: ...

  6. 【译】:lxml.etree官方文档

    本文翻译自:http://lxml.de/tutorial.html, 作者:Stefan Behnel 这是一个关于使用lxml.etree进行XML处理的教程.它简要介绍了ElementTree ...

  7. linux 部署python

    tar xf Python-.tar.xz cd Python-./configure make make install ln -s /usr/local/bin/python2. /usr/bin ...

  8. vue项目组件的全局注册

    在vue-cli项目中,我们经常会封装自己的组件,并且要在多个界面中引用它,这个时候就需要全局注册组件. 首先我们会封装自己的组件,比如twoDimensionTable文件夹下的index.vue: ...

  9. es6基础入门变量的解构赋值

    let [a, b, c] = [1, 2, 3]; let [foo, [[bar], baz]] = [1, [[2], 3]]; foo bar baz let [ , , third] = [ ...

  10. python--*args和**kwargs可变参数

    先来看个例子: #! /usr/bin/env python #coding=utf-8 def foo(*args, **kwargs): print('args=',args) print('kw ...