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)最开始的思路 一开始的想法是很简单的,找出每一行的高度,然后一行一行 ...
随机推荐
- Linux学习之系统的构建
实验环境:ubuntu 12.04 LTS 内核版本:linux-3.9.4 因为一直以来都对Linux的工作机理比较感兴趣,所以正好这两天有机会好好的研究一下,那闲话不多说,直接进入正题. 俗话说的 ...
- axis1,xfire,jUnit 测试案列+开Web Service开发指南+axis1.jar下载 代码
axis1,xfire,jUnit 测试案列+Web Service开发指南(中).pdf+axis1.jar下载 代码 项目和资源文档+jar 下载:http://download.csdn. ...
- linux 高精度定时器例子
//author:DriverMonkey //phone:13410905075 //mail:bookworepeng@Hotmail.com //qq:196568501 #include &l ...
- grub 的安装与使用
安装与使用grub 要开始探究 GRUB 的精妙之处,首先需要下载.编译和安装它.但不要害怕 -- 根本不会修改您的引导记录 -- 我们只是要编译和安装 GRUB,就像其它程序一样,在此过程中我们可以 ...
- 用curl访问HTTPS站点并登录
开发网站,少不了测试.现在的网站为了加强安全性,都启用了HTTPS协议.所谓HTTPS,也就是HTTP文本在SSL协议中传输.用curl命令行来测试HTTPS站点是个很有用的功能,写点脚本,就可以做功 ...
- kubernetes service分析
service type k8s中service主要有三种: ClusterIP: use a cluster-internal IP only - this is the default and i ...
- mybatis 入门优化
在上一节<mybatis快速入门>的基础上对IWebUserDao的实现类进行了优化,暂时命名为WebUserDaoMybatis2.java package com.mozi.dao.i ...
- 用vue实现简单实时汇率计算功能
最近在自己摸索vue的使用,因为相对于只是去看教程和实例,感觉不如自己动手写一个demo入门来的快.刚好看到小程序中有一个简单但是很精致的应用极简汇率,而且它的表现形式和vue的表现形式很像,于是想着 ...
- php文件上传及头像预览
php文件上传原理是通过form表单的enctype="multipart/form-data"属性将文件临时放到wamp文件夹中的tmp目录下,再通过后台php 程序将文件保存在 ...
- [ios2][转]iOS摇动检测 (UIAccelerometer)
加速计(UIAccelerometer)是一个单例模式的类,所以需要通过方法sharedAccelerometer获取其唯一的实例. 加速计需要设置的主要有两个: 一个是设置其代理,用以执行获取加速计 ...