当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET通过Remoting service上传文件

ASP.NET通过Remoting service上传文件

2018年04月29日  | 移动技术网IT编程  | 我要评论

兴义市邮编,晴朗吉他谱,康乐县人民政府网

最近在因为在学习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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网