乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      C# Remoting的一個簡單例子

       水底の小魚 2009-05-06
       
      2007-10-26 09:07
      .Net對于遠程調(diào)用提供了兩種方法:Remoting和WebService。
      WebService現(xiàn)在是如火如荼,特別是有一種比較流行的架構(gòu):Winform+WebService(Java、.Net),
      我曾經(jīng)做過的一個項目就是這樣子的,分布式、跨平臺、極佳的用戶體驗,這三者結(jié)合起來是不是很誘人?
      不過,這里我只說Remoting,Remoting具有以下特點:
      1、Tcp通道的Remoting速度非???br>2、雖然是遠程的,但是非常接近于本地調(diào)用對象
      3、可以做到保持對象的狀態(tài)
      4、沒有應用程序限制,可以是控制臺,winform,iis,windows服務承載遠程對象
      缺點:
      1、不是標準的應用,因此有平臺限制
      2、脫離iis的話需要有自己的安全機制
      可以看出來,比起WebService,Remoting更適合于中小型局域網(wǎng)應用,而不適用于企業(yè)級的應用。
      下面給出一個極其簡單的Sample:
      Remoting用的對象:
      1namespace RemoteSample
      2{
      3    public class RemoteObject : System.MarshalByRefObject
      4    {
      5        public RemoteObject()
      6        {
      7             System.Console.WriteLine("New Referance Added!");
      8         }

      9
      10        public int sum(int a, int b)
      11        {
      12            return a + b;
      13         }

      14     }

      15}
      將其編譯為一個lib文件:csc /t:library RemoteObject.cs

      Server端:
      1using System;
      2using System.Runtime;
      3using System.Runtime.Remoting;
      4using System.Runtime.Remoting.Channels;
      5using System.Runtime.Remoting.Channels.Tcp;
      6using RemoteSample;
      7
      8namespace RemoteSampleServer
      9{
      10    public class RemoteServer
      11    {
      12        public static void Main(String[] args)
      13        {
      14              TcpServerChannel channel = new TcpServerChannel(6666);
      15              ChannelServices.RegisterChannel(channel);
      16              RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject),
      17                 "RemoteObject", WellKnownObjectMode.SingleCall);
      18              System.Console.WriteLine("Press Any Key");
      19              System.Console.ReadLine();
      20          }

      21     }

      22}
      將其編譯為一個exe文件:csc /r:System.Runtime.Remoting.dll /r:RemoteObject.dll RemoteServer.cs

      Client端:
      1using System;
      2using System.Runtime.Remoting;
      3using System.Runtime.Remoting.Channels;
      4using System.Runtime.Remoting.Channels.Tcp;
      5using RemoteSample;
      6
      7namespace RemoteSampleClient
      8{
      9    public class RemoteClient
      10    {
      11        public static void Main(string[] args)
      12        {
      13             ChannelServices.RegisterChannel(new TcpClientChannel());
      14             RemoteObject remoteobj = (RemoteObject)Activator.GetObject(typeof(RemoteObject),
      15            "tcp://localhost:6666/RemoteObject");
      16             Console.WriteLine("1 + 2 = " + remoteobj.sum(1,2).ToString());
      17             Console.ReadLine();
      18         }

      19     }

      20}
      同樣的,將其編譯為exe文件:csc /r:System.Runtime.Remoting.dll /r:RemoteObject.dll RemoteClient.cs

      好了,一次運行生成的RemoteServer.exe和RemoteClient.exe,你就會發(fā)現(xiàn)原來Remoting是這樣簡單。

        本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多