Remote小Demo
Demo基于http://www.cnblogs.com/zhili/p/NETRemoting.html

RemotingObj
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Metadata;
using System.Text;
using System.Threading.Tasks; namespace RemotingServer
{
public class RemotingObject:MarshalByRefObject
{
public int TestTcpAdd(int first,int second)
{
return first + second;
} public int TestHttpMinus(int first,int second)
{
return first - second;
} [SoapMethod(XmlNamespace = "RemotingServer", SoapAction = "RemotingServer#TestMultiIpc")]
public int TestMultiIpc(int first, int second)
{
return first*second;
}
}
}
RemotingServer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Channels.Ipc;
using System.Runtime.Remoting.Channels.Tcp;
using System.Text;
using System.Threading.Tasks; namespace RemotingServer
{
class Program
{
static void Main(string[] args)
{
TcpChannel tcpChannel = new TcpChannel(2046);
HttpChannel httpChannel = new HttpChannel(9001);
IpcChannel ipcChannel = new IpcChannel("IpcTest"); ChannelServices.RegisterChannel(tcpChannel,false);
ChannelServices.RegisterChannel(httpChannel,false);
ChannelServices.RegisterChannel(ipcChannel,false); Console.WriteLine("The name of the Tcp Channel:{0}",tcpChannel.ChannelName);
Console.WriteLine("The priority of the Tcp Channel:{0}",tcpChannel.ChannelPriority); Console.WriteLine("The name of the Http Channel:{0}",httpChannel.ChannelName);
Console.WriteLine("The priority of the Http Channel:{0}",httpChannel.ChannelPriority); Console.WriteLine("The name of IPC Channel :{0}",ipcChannel.ChannelName);
Console.WriteLine("The priority of Ipc Channel:{0}",ipcChannel.ChannelPriority); RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingServer.RemotingObject), "RemotingObject",WellKnownObjectMode.Singleton);
Console.ReadKey();
}
}
}
RemotingClinet
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RemotingServer; namespace RemotingClient
{
class Program
{
static void Main(string[] args)
{
RemotingObject proxyTcp =
Activator.GetObject(typeof (RemotingObject), "tcp://localhost:2046/RemotingObject") as RemotingObject;
if (proxyTcp == null)
{
Console.WriteLine("连接Tcp服务失败!");
return; } RemotingObject proxyHttp =
Activator.GetObject(typeof(RemotingObject), "http://localhost:9001/RemotingObject") as RemotingObject;
if (proxyHttp==null)
{
Console.WriteLine("连接Http服务失败!");
return;
} RemotingObject proxyIpc =
Activator.GetObject(typeof(RemotingObject), "ipc://IpcTest/RemotingObject") as RemotingObject;
if (proxyIpc == null)
{
Console.WriteLine("连接IPC失败!");
return;
} // 输出信息
Console.WriteLine("This call object by TcpChannel, 100 + 200 = {0}", proxyTcp.TestTcpAdd(100, 200));
Console.WriteLine("This call object by HttpChannel, 100 - 200 = {0}", proxyHttp.TestHttpMinus(100, 200));
Console.WriteLine("This call object by IpcChannel, 100 * 200 = {0}", proxyIpc.TestMultiIpc(100, 200));
Console.WriteLine("Press any key to exit!");
Console.ReadLine();
}
}
}
备注:
Remoting在HttpChannel下抛“指定的 SOAPAction 无效
解决方法:
1:将Server和Client所在的程序集修改成相同的程序集名。
http://blog.csdn.net/lilin8905/article/details/6232640
2:在需要使用httpChannel的方法上面加上SoapMethod标签
[SoapMethod(XmlNamespace = "命名空间", SoapAction = "命名空间#方法名")]
http://blog.csdn.net/sloder/article/details/8694560
Remote小Demo的更多相关文章
- 新手 gulp+ seajs 小demo
首先,不说废话,它的介绍和作者就不在多说了,网上一百度一大堆: 我在这里只是来写写我这2天抽空对seajs的了解并爬过的坑,和实现的一个小demo(纯属为了实现,高手请绕道); 一.环境工具及安装 1 ...
- Nancy之基于Nancy.Hosting.Self的小Demo
继昨天的Nancy之基于Nancy.Hosting.Aspnet的小Demo后, 今天来做个基于Nancy.Hosting.Self的小Demo. 关于Self Hosting Nancy,官方文档的 ...
- Nancy之基于Nancy.Owin的小Demo
前面做了基于Nancy.Hosting.Aspnet和Nancy.Hosting.Self的小Demo 今天我们来做个基于Nancy.Owin的小Demo 开始之前我们来说说什么是Owin和Katan ...
- Nancy之基于Self Hosting的补充小Demo
前面把Hosting Nancy with ASP.NET.Self Hosting Nancy和Hosting Nancy with OWIN 以demo的形式简单描述了一下. 这篇是为Self H ...
- [Unity3D]做个小Demo学习Input.touches
[Unity3D]做个小Demo学习Input.touches 学不如做,下面用一个简单的Demo展示的Input.touches各项字段,有图有真相. 本项目已发布到Github,地址在(https ...
- Android -- 自定义View小Demo,动态画圆(一)
1,转载:(http://blog.csdn.NET/lmj623565791/article/details/24500107),现在如下图的效果: 由上面的效果图可以看到其实是一个在一个圆上换不同 ...
- Win10 FaceAPI小demo开发问题汇总
Win10 FaceAPI小demo开发问题汇总 最近使用微软牛津计划做一个小demo,使用FaceAPI做一个小应用,实现刷脸的功能.开发的过程中用到几个问题,具体如下: Stream 与IRand ...
- 模仿京东顶部搜索条效果制作的一个小demo
最近模仿京东顶部搜索条效果制作的一个小demo,特贴到这里,今后如果有用到可以参考一下,代码如下 #define kScreenWidth [UIScreen mainScreen].bounds.s ...
- Android学习小Demo一个显示行线的自定义EditText
今天在处理一个EditText的时候,想着把EditText做成像一本作业本上的纸一样,每一行都可以由线条隔开,具体效果如下: 1)最开始的思路 一开始的想法是很简单的,找出每一行的高度,然后一行一行 ...
随机推荐
- .NET:国际化和本地化
.NET:国际化和本地化 背景 国际化(i18n)和本地化(l10n)是高端程序的必备技术,可惜从业五年从没有尝试过,下一步准备做一个多用户的博客系统,想支持多语言,今天就学习了一下,写出来,希望大家 ...
- python cookbook学习1
python cookbook学习笔记 第一章 文本(1) 1.1每次处理一个字符(即每次处理一个字符的方式处理字符串) print list('theString') #方法一,转列表 结果:['t ...
- html5基础的常用的技巧
html5基础的常用的技巧 1. 新的Doctype声明 XHTML的声明太长了,我相信很少会有前端开发人员能手写出这个Doctype声明. <!DOCTYPE html PUBLIC &quo ...
- [修]开启MySQL远程访问权限 允许远程连接
原文地址:http://www.cnblogs.com/XL-Liang/archive/2012/05/03/2481310.html 这个地址也许更有帮助:http://www.cppblog.c ...
- 【Linux】Shell学习笔记之四——文件和目录管理(硬连接和软连接)
在这节将要学习linux的连接档,在之前用"ls -l" 查看文件属性的命令时, 其中第二个属性是连接数.那么这个连接数是干什么的?这就要理解inode. 先说一下文件是怎么存储的 ...
- 使用Freemarker创建word文档
最近做一个项目,本来是直接在网页上查看文本信息,然后给客户直接打印的,但是发现也许是浏览器还是打印机的原因,总之,有个客户打印出来的格式始终与其他的不同,没办法,最后想到了直接将数据库中的信息生成一个 ...
- 【翻译】Asp.net Core介绍
ASP.NET Core is a significant redesign of ASP.NET. This topic introduces the new concepts in ASP.NET ...
- linux服务器开发二(系统编程)--进程相关
进程相关的概念 程序与进程 程序,是指编译好的二进制文件,在磁盘上,不占用系统资源(CPU.内存.打开的文件.设备.锁等等). 进程,是一个抽象的概念,与操作系统原理联系紧密.进程是活跃的程序,占用系 ...
- Mybatis学习笔记(一) 之框架原理
原生态JDBC编程中问题总结 1.单独使用jdbc连接数据库 maven依赖包: <!-- mysql --> <dependency> <groupId>mysq ...
- action = "#" 是什么意思 在HTML语言中
action = "#" 是form标签的属性,代表提交数据到本页,如:// 提交数据到a.aspx页面<form action="a.aspx"> ...