All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
在Win2003,R2上安装SQL,Server,2005(一)_mssql学习_编程技术
在.NET中嵌入和使用资源文件_[Asp.Net教程]
SQL,SERVER2008安装_mssql学习_编程技术
(javascript)prototype的一个优势也是缺点_JavaScript技术_编程技术
.Net中使用GDI+提高gif图片画质的代码_[Asp.Net教程]
Delphi带历史信息的菜单实例
ajax实现无刷新验证用户名是否存在_[AJAX教程]
浅谈当下网页设计趋势_优化技巧_seo学堂
网友分享:TopStyle Pro 的使用技巧_[Html教程]
SQL数据操作基础(中级)6_mssql学习_编程技术
Reading number is top 10 pictures
含苞欲放的素颜美少女1
Female model behind the bitterness, often being overcharged5
人美胸美腿更美4
Sora aoi mirror memorial classics2
The money of more than 100 countries and regions19
NeedWallpaper12
Sora aoi after swimming
The sixties of the last century, China is such a kill pig
美女浴室写真3
关于海盗的研究2
Download software ranking
linux高级编程
Ashlynn Video4
Boxer vs Yellow5
Boxer's Top ten classic battle3
星际争霸1.08硬盘免安装版
jdk1.5
dreamweaver8中文版
Tram sex maniac 2 (H) rar bag1
The hero
XML+Web+Service开发教程
delv published in(发表于) 2014/1/6 9:05:04 Edit(编辑)
ASP.NET通过Remoting,service上传文件_[Asp.Net教程]

ASP.NET通过Remoting,service上传文件_[Asp.Net教程]

ASP.NET通过Remoting service上传文件_[Asp.Net教程]

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







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.