仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 972|回复: 9
打印 上一主题 下一主题

[学习教程] ASP.NET网页设计ASP.NET经由过程Remoting service上传文件

[复制链接]
变相怪杰 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:37:50 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
2003年中微软发布最新版本的ASP.netWebMatrix,对于我们喜欢用Asp.net来编程的朋友实在是个好消息,我也实实在在的将Asp.net更深入的研究了一下,以方便我以后更好的运用它,同时我也讲讲使用它的感受。asp.net|上传比来在由于在进修Remoting,地道只是懂得一下,发明Remoting的确是好器材。
我们一般有三种体例来利用remoting,一种是
第一种:Publishingapublicobject
公然的工具创立在当地
第二种:Remotecreationofapublicobject(SAO)
工具创立在客户端哀求中
第三种:Remotecreationofaprivateobject(CAO)
工具创立在HOST上,客户端援用服务器上的工具
目录我也没有很好了解这三种的实质区分在那里。而这三种体例的remoting创立体例也不不异。
第一种体例
Host:
ChannelServices.RegisterChannel(newTcpChannel(1500));
cTransferTrans=newcTransfer();
RemotingServices.Marshal(Trans,"TestService");Client:
cTransferT=(cTransfer)Activator.GetObject(typeof(cTransfer),
"tcp://host:1500/TestService");
第二种体例
Host:
ChannelServices.RegisterChannel(newTcpChannel(1500));
RemotingConfiguration.RegisterWellKnownServiceType(typeof(cTransfer),
"TestService",WellKnownObjectMode.Singleton);Client:
cTransferT=(cTransfer)Activator.GetObject(typeof(cTransfer),
"tcp://host:1500/TestService");
第三种体例
Host:
ChannelServices.RegisterChannel(newTcpChannel(1500));
RemotingConfiguration.RegisterActivatedServiceType(typeof(cTransfer));Client:
object[]attr={newUrlAttribute("tcp://host:1500")};
object[]args={"Sampleconstructorargument"};
cTransferT=(cTransfer)Activator.CreateInstance(typeof(cTransfer),args,attr);
假如我们必要一个工具(object)同意远程挪用处置,那末这个工具(object)必要承继于MarshalByRefObject这个类。
怎样在remoting中传送文件呢?基础思绪就是在client翻开client的文件,转换在Byte[]范例以后挪用host的工具。
Client与Host之间传送的工具
[Serializable]
publicstructkAction
{
publicstringfilename;
publicbyte[]context;

};翻开文件,将流字节保留到Context中往
StreamfileStream=File.Open(this.transFileName.Text,FileMode.Open);
fileStream.Position=0;
byte[]Content=newbyte[((int)fileStream.Length)+1];
fileStream.Read(Content,0,Content.Length);
在Host在读取到Kaction以后,把它保留到指定文件夹上面
MemoryStreammeoeryStream=newMemoryStream(k_Action.context);
FileStreamfileStream=newFileStream(@"d:"+k_Action.filename,FileMode.Create);
meoeryStream.WriteTo(fileStream);
fileStream.Close();
meoeryStream.Close();
发明不克不及在工具中又界说新的工具。在筹办发送到HOST上会提醒“包括潜伏伤害的范例”。
[Serializable]
publicstructkAction
{
publicstringfilename;
publicbyte[]context;
publicFineInfofileInfo;//这里
};
纪录一下本人的心得。有空我会好好收拾下下回做篇完全点的。
cnzcsblogs
学习asp.net两个月有余了,除了对html、web控件比较熟悉(应该是说都能理解和接受)之外,竟不知道自己还会什么。看了两本书:《精通asp.net网络编程》(人民邮电出版社)、《asp.net实用案例教程》(清华大学出版社)。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-9 07:00

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表