日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

.NET Remoting Basic(6)-配置文件

發(fā)布時間:2025/4/14 asp.net 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .NET Remoting Basic(6)-配置文件 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

????? 除了以硬編碼的形式來注冊對象,也可以以配置文件的方式來注冊,以便增加靈活性

1.服務(wù)器端配置文件

其中以system.runtime.remoting 為配置節(jié)點

配置了信道和注冊對象,看起來非常的容易理解

<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.客戶端同樣是采用配置文件

不過節(jié)點為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.定義服務(wù)器端對象代理

需加上SoapTypeSoapMethod來表示這個對象

[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();}

轉(zhuǎn)載于:https://www.cnblogs.com/Clingingboy/archive/2010/08/26/1809575.html

總結(jié)

以上是生活随笔為你收集整理的.NET Remoting Basic(6)-配置文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。