免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
C# Remoting的一個(gè)簡(jiǎn)單例子
 
2007-10-26 09:07
.Net對(duì)于遠(yuǎn)程調(diào)用提供了兩種方法:Remoting和WebService。
WebService現(xiàn)在是如火如荼,特別是有一種比較流行的架構(gòu):Winform+WebService(Java、.Net),
我曾經(jīng)做過的一個(gè)項(xiàng)目就是這樣子的,分布式、跨平臺(tái)、極佳的用戶體驗(yàn),這三者結(jié)合起來(lái)是不是很誘人?
不過,這里我只說(shuō)Remoting,Remoting具有以下特點(diǎn):
1、Tcp通道的Remoting速度非???br>2、雖然是遠(yuǎn)程的,但是非常接近于本地調(diào)用對(duì)象
3、可以做到保持對(duì)象的狀態(tài)
4、沒有應(yīng)用程序限制,可以是控制臺(tái),winform,iis,windows服務(wù)承載遠(yuǎn)程對(duì)象
缺點(diǎn):
1、不是標(biāo)準(zhǔn)的應(yīng)用,因此有平臺(tái)限制
2、脫離iis的話需要有自己的安全機(jī)制
可以看出來(lái),比起WebService,Remoting更適合于中小型局域網(wǎng)應(yīng)用,而不適用于企業(yè)級(jí)的應(yīng)用。
下面給出一個(gè)極其簡(jiǎn)單的Sample:
Remoting用的對(duì)象:
1
namespace 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
}
將其編譯為一個(gè)lib文件:csc /t:library RemoteObject.cs

Server端:
1
using System;
2
using System.Runtime;
3
using System.Runtime.Remoting;
4
using System.Runtime.Remoting.Channels;
5
using System.Runtime.Remoting.Channels.Tcp;
6
using RemoteSample;
7

8
namespace 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
}
將其編譯為一個(gè)exe文件:csc /r:System.Runtime.Remoting.dll /r:RemoteObject.dll RemoteServer.cs

Client端:
1
using System;
2
using System.Runtime.Remoting;
3
using System.Runtime.Remoting.Channels;
4
using System.Runtime.Remoting.Channels.Tcp;
5
using RemoteSample;
6

7
namespace 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

好了,一次運(yùn)行生成的RemoteServer.exe和RemoteClient.exe,你就會(huì)發(fā)現(xiàn)原來(lái)Remoting是這樣簡(jiǎn)單。
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
.NET Remoting編程簡(jiǎn)介
C# 使用MarshalByRefObject跨程序調(diào)用方法
回顧.NET Remoting分布式開發(fā)
跟我一起學(xué)WCF(2)
.net 真實(shí)代理和透明代理的交互
c 制作dll文件
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服