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

首頁 > 編程 > .NET > 正文

ASP.NET通過Remoting service上傳文件

2024-07-10 13:10:48
字體:
來源:轉載
供稿:網友

最近在因為在學習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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汤原县| 新蔡县| 嵊州市| 新河县| 新营市| 寿光市| 宝应县| 锡林浩特市| 岚皋县| 五莲县| 新田县| 靖边县| 遂宁市| 湘西| 桃江县| 石台县| 承德市| 东乌珠穆沁旗| 阿克苏市| 遂昌县| 阿拉善右旗| 万载县| 东台市| 东港市| 郧西县| 静安区| 望奎县| 正镶白旗| 图木舒克市| 上高县| 龙陵县| 龙南县| 青龙| 出国| 仙游县| 河东区| 老河口市| 襄垣县| 什邡市| 沈丘县| 梁平县|