国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

通過Remoting service上傳文件

2019-11-18 17:14:19
字體:
來源:轉載
供稿:網友

最近在因為在學習Remoting,純粹只是了解一下,發現Remoting確實是好東西。

我們通常有三種方式來使用remoting,一種是

第一種:Publishing a public object
公開的對象創建在本地
第二種:Remote creation of a public object (SAO)
對象創建在客戶端請求中
第三種:Remote creation of a PRivate object (CAO)
對象創建在HOST上,客戶端引用服務器上的對象

目次我也沒有很好理解這三種的本質區別在哪里。而這三種方式的remoting創建方式也不相同。

第一種方式
Host:
ChannelServices.RegisterChannel (new TcpChannel(1500));
cTransfer Trans = new cTransfer();
RemotingServices.Marshal (Trans, "TestService");Client:
cTransfer T = (cTransfer) Activator.GetObject(typeof(cTransfer),
                                 "tcp://host:1500/TestService");
第二種方式
Host:
ChannelServices.RegisterChannel (new TcpChannel(1500));
RemotingConfiguration.RegisterWellKnownServiceType(typeof(cTransfer),
    "TestService", WellKnownObjectMode.Singleton);Client:
cTransfer T = (cTransfer) Activator.GetObject(typeof(cTransfer),
                                 "tcp://host:1500/TestService");
第三種方式
Host:
ChannelServices.RegisterChannel (new TcpChannel(1500));
RemotingConfiguration.RegisterActivatedServiceType(typeof(cTransfer));Client:
object[] attr = {new UrlAttribute("tcp://host:1500")};
object[] args = {"Sample constructor argument"};
cTransfer T = (cTransfer) Activator.CreateInstance(typeof(cTransfer), args, attr);
如果我們需要一個對象(object)允許遠程調用處理,那么這個對象(object)需要繼承于MarshalByRefObject這個類。

如何在remoting中傳送文件呢?基本思路就是在client打開client的文件,轉換在Byte[]類型之后調用host的對象。
Client與Host之間傳送的對象
[Serializable]
    public struct kAction
    {
        public string filename;
        public byte[] context;       
       
    };打開文件,將流字節保存到Context中去
Stream  fileStream=File.Open(this.transFileName.Text,FileMode.Open);
            fileStream.Position=0;
            byte[] Content = new byte[((int) fileStream.Length) + 1];
            fileStream.Read(Content,0,Content.Length) ;
在Host在讀取到Kaction之后,把它保存到指定文件夾下面
MemoryStream meoeryStream=new MemoryStream(k_Action.context);
            FileStream fileStream=new FileStream(@"d:/"+k_Action.filename,FileMode.Create);
            meoeryStream.WriteTo(fileStream);
            fileStream.Close();
            meoeryStream.Close();           
發現不能在對象中又定義新的對象。在準備發送到HOST上會提示“包含潛在危險的類型”。
[Serializable]
    public struct kAction
    {
        public string filename;
        public byte[] context;
                public FineInfo fileInfo;//這里

    };
記錄一下自己的心得。有空我會好好整理下下回做篇完整點的。

cnzc's blogs


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东宁县| 西宁市| 安顺市| 西和县| 鸡东县| 平舆县| 昭觉县| 赤水市| 绥棱县| 清镇市| 建平县| 那坡县| 博客| 靖安县| 长子县| 桂东县| 阳信县| 彝良县| 华亭县| 百色市| 武陟县| 连江县| 南昌县| 小金县| 白水县| 西盟| 琼结县| 平塘县| 新民市| 彩票| 东平县| 射洪县| 裕民县| 永年县| 新闻| 永和县| 兴海县| 西宁市| 荣成市| 枝江市| 惠安县|