.NET Remoting Basic(6)-配置文件
除了以硬编码的形式来注册对象,也可以以配置文件的方式来注册,以便增加灵活性
1.服务器端配置文件
其中以system.runtime.remoting 为配置节点
配置了信道和注册对象,看起来非常的容易理解
<configuration><system.runtime.remoting><application><channels><channel ref="http" port="1234" /></channels><service><wellknown mode="Singleton" type="Server.CustomerManager, Server" objectUri="CustomerManager.soap" /></service></application></system.runtime.remoting></configuration>
2.Server端代码
static void Main(string[] args){Console.WriteLine ("ServerStartup.Main(): Server started");String filename = "server.exe.config";RemotingConfiguration.Configure(filename);// the server will keep running until keypress.Console.ReadLine();}
3.客户端同样是采用配置文件
不过节点为client
<configuration><system.runtime.remoting><application><client><wellknown type="Server.CustomerManager, Client" url="http://localhost:1234/CustomerManager.soap" /></client></application></system.runtime.remoting></configuration>
4.定义服务器端对象代理
需加上SoapType和SoapMethod来表示这个对象
[Serializable, SoapType(XmlNamespace=@"http://schemas.microsoft.com/clr/nsassem/Server/Server%2C%20Version%3D1.0.1584.30404%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull", XmlTypeNamespace=@"http://schemas.microsoft.com/clr/nsassem/Server/Server%2C%20Version%3D1.0.1584.30404%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull")]public class CustomerManager : System.MarshalByRefObject{[SoapMethod(SoapAction=@"http://schemas.microsoft.com/clr/nsassem/Server.CustomerManager/Server#GetCustomer")]public General.Customer GetCustomer(Int32 id){return((General.Customer) (Object) null);}}
5.客户端访问
static void Main(string[] args){String filename = "client.exe.config";RemotingConfiguration.Configure(filename);CustomerManager mgr = new CustomerManager();Console.WriteLine("Client.Main(): Reference to CustomerManager acquired");Customer cust = mgr.GetCustomer(4711);int age = cust.GetAge();Console.WriteLine("Client.Main(): Customer {0} {1} is {2} years old.",cust.FirstName,cust.LastName,age);Console.ReadLine();}
6.以接口形式访问
6.1先读取客户端配置文件接口对象
class RemotingHelper{private static IDictionary _wellKnownTypes;public static Object CreateProxy(Type type){if (_wellKnownTypes == null) InitTypeCache();WellKnownClientTypeEntry entr = (WellKnownClientTypeEntry)_wellKnownTypes[type];if (entr == null){throw new RemotingException("Type not found!");}return Activator.GetObject(entr.ObjectType, entr.ObjectUrl);}public static void InitTypeCache(){Hashtable types = new Hashtable();foreach (WellKnownClientTypeEntry entr inRemotingConfiguration.GetRegisteredWellKnownClientTypes()){if (entr.ObjectType == null){throw new RemotingException("A configured type could not " +"be found. Please check spelling in your configuration file.");}types.Add(entr.ObjectType, entr);}_wellKnownTypes = types;}}
6.2客户端获取
static void Main(string[] args){String filename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;RemotingConfiguration.Configure(filename);IRemoteCustomerManager mgr = (IRemoteCustomerManager) RemotingHelper.CreateProxy(typeof(IRemoteCustomerManager));Console.WriteLine("Client.Main(): Reference to rem.obj. acquired");Customer cust = mgr.GetCustomer(42);Console.WriteLine("Retrieved customer {0} {1}", cust.FirstName,cust.LastName);Console.ReadLine();}
转载于:https://www.cnblogs.com/Clingingboy/archive/2010/08/26/1809575.html
.NET Remoting Basic(6)-配置文件相关推荐
- Remoting技术使用配置文件示例
1.创建类库工程RemotableType.dll (提供remotable 类型). RemotableType.cs using System; using System.Collections. ...
- 远程处理Remoting
日程 ?应用程序域 ?Remoting和原理 ?编程式和管理式配置实例 用应用程序域 操作系统和运行库环境通常会在应用程序间提供某种形式的隔离.例如,Microsoft Windows 使用进程来隔离 ...
- WCF分布式开发必备知识(2):.Net Remoting
上一节我们学习了网络分布式编程中的MSMQ消息队列技术.本节我们将学习分布式编程的另外一个重要的技术.Net Remoting,文章的结构还是先讨论基本概念,再来探讨具体的技术实现,希望能和大家一起交 ...
- Remoting 配置格式说明(转)
使用配置文件的好处是什么?很简单,他可以简化代码,可以随时更改,通道,端口,URL的设置不需要重新编译就可以运行.所以在实际项目中经常采用这种方式. 怎么写一个服务器端的配置文件? 下面举个例子: & ...
- 使用.NET Remoting开发分布式应用——基于租约的生存期(转载)
使用.NET Remoting开发分布式应用--基于租约的生存期 一.概述 知名类型的SingleCall对象可以在客户程序的方法调用之后被垃圾收集器清理掉,因为它没有保持状态,属于无状态的.而客户激 ...
- java httpinvoker漏洞_Spring HttpInvoker 服务端安全验证的和客户端请求配置
1.服务端 服务Java接口 package service; public interface TestService { int add(int i,int j); } 服务的Java实现 pac ...
- RPC(Remote Procedure Calls)远程过程调用
很长时间以来都没有怎么好好搞清楚RPC(即Remote Procedure Call,远程过程调用)和HTTP调用的区别,不都是写一个服务然后在客户端调用么?这里请允许我迷之一笑~Naive!本文简单 ...
- apache 配置 中英
2019独角兽企业重金招聘Python工程师标准>>> 文章简介:Apache最新官方配置文件中文版.帮忙web服务器管理员更方便的对Apache进行配置. # # Based up ...
- Linux常见的文件内容查找和替换命令
在Linux服务器部署和运维过程中,经常出现需要查找或者批量替换某个配置文件,这个时候,借用Linux的一些基础命令,来提高工作效率. 1.vi命令下的查找和替换 1.1 vi下的查找 比如有个bas ...
最新文章
- 【机器学习基石笔记】八、噪声和错误
- ASP.NET--Menu控件
- python学习有哪些方向可以选择_学习Python后都有哪些发展方向?
- python处理excel大数据-Python实现大数据收集至excel的思路详解
- 常用的排序算法的时间复杂度和空间复杂度
- 成功解决Future Warning: The sklearn.neighbors.dist_metrics module is deprecated in version 0.22 and wil
- struts2 去掉或修改后缀名
- hbase1.1.1 连接集群_Hadoop2.7.1+Hbase1.1.2集群环境搭建(10) hadoop hbase kerberos
- centos7下SVN服务器搭建
- Python 爬虫-BeautifulSoup
- 使用cgroup限制某个程序对内存的使用
- 高中计算机学考题库,高中信息技术学业水平考试试题汇总(含答案)
- PHP字符串函数strrchr(查找指定字符在字符串中的最后一次出现)
- ArcGIS Runtime SDK for Android 读取tpk、vtpk
- 2021-09-10 LeetCode1894-找到需要补充粉笔的学生编号(每日一题)
- 聊一聊推荐系统中ExploitExplore算法
- OS App体验设计
- JSON格式转MAP的6种方法
- SCT2330CTVBR
- 为你揭秘,希格斯玻色子如何赋予粒子质量
热门文章
- jbuilder2006注册机
- 【IM】关于多任务学习的理解
- MapReduce基础开发之十一DistributedCache使用
- Android异步加载
- numpy and pandas
- spring框架的概述以及spring中基于XML的IOC配置——概念
- 类型转换与采样 || SMOTE算法
- java.lang.Thread 和 java.lang.Runnable的区别
- SQL Server2019数据库查询所有数据库名、表名、表结构、表字段、主键方法演示,执行sql提示对象名‘user_tab_columns‘、 ‘user_cons_columns‘ 无效问题解决
- Python 知识点笔记:走进面向对象