上载&使用Silverlight&的多个文件世界足球联合会 [英] Uploading large & multiple files using silverlight & WCF

查看:120
本文介绍了上载&使用Silverlight&的多个文件世界足球联合会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图使用silverlight应用程序和WCF服务上传多个大文件.

我的问题是我不能上传大于60 MB的文件

我正在使用basicHttpbinding并进行流式传输..据我所知,我无法使用MTOM进行消息编码

我在Google上搜索了很多,发现有一些示例可以上传单个大文件...但是不知道如何上传多个文件

所以请您帮我解决这个问题

谢谢

Hi,

I was trying to upload multiple files of large size using silverlight application and WCF service

my problem is that I can not upload files larger than 60 MB

I am using basicHttpbinding and streamed ..and asfar as I know I can not use MTOM for Message encoding

I googled a lot and found there are samples which can upload single file of large size...but don''t know how to upload multiple files

so some body could you please help me in solving this

Thanks

推荐答案

您可能必须在服务web.config中更改最大缓冲区大小.

要上传多个文件,只需为每个文件调用Web服务.
You may have to change the max buffer size in your service web.config.

To upload multiple files, simply call your web service for each file.


感谢您的回复

我们已经尝试过增加缓冲区大小

所取的最大值是60MB

但是我们需要上传1到3 GB大小的文件

所以我们使用的是将大文件切成小块,然后上传

但随后它可能会上传第一个文件,而无法上传下一个文件

看起来问题出在uploadasync方法上

但这就是应该上传多个文件的方式

也是我们的问题是我们无法调试代码

silverlight应用程序可以分块发送

问题是在WCF服务上如何处理将块写入正确的文件

我在这里粘贴代码

Web.config
--------------

< < system.web>
< httpRuntime maxRequestLength ="2147483647"/>
<!-
将编译设置为debug ="true"以插入调试
符号插入已编译的页面.因为这个
影响性能,将此值仅设置为true
在开发过程中.
->
< compilation debug ="true" targetFramework ="4.0">
</compilation>
<!-
< authentication>部分启用配置

使用的安全认证模式的说明 ASP.NET识别传入的用户.
->
< authentication mode ="Windows"/>
<!-
< customErrors>部分启用配置
/发生未处理的错误时该怎么办
在执行请求期间.具体来说,
它使开发人员可以配置html错误页面
将显示以代替错误堆栈跟踪.
< customErrors mode ="RemoteOnly" defaultRedirect ="GenericErrorPage.htm">
<错误statusCode ="403" redirect ="NoAccess.htm"/>
<错误statusCode ="404" redirect ="FileNotFound.htm"/>
</customErrors>
->
< pages controlRenderingCompatibilityVersion ="3.5" clientIDMode ="AutoID"/>
</system.web>
<!-
要在Internet下运行ASP.NET AJAX,必须使用system.webServer部分. 信息服务7.0. IIS的早期版本没有必要.
->
< system.serviceModel>
< serviceHostingEnvironment aspNetCompatibilityEnabled ="true"/>
< bindings>
< basicHttpBinding>
< binding name ="TransportServiceBinding" maxBufferSize ="2147483647" maxBufferPoolSize ="5242880000"
maxReceivedMessageSize ="2147483647" receiveTimeout ="10:10:00" sendTimeout ="10:10:00"
openTimeout ="10:10:00" closeTimeout ="10:10:00"
transferMode ="StreamedResponse">
< readerQuotas maxArrayLength ="2147483647" maxStringContentLength ="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
-------------------------------------------------- --------
我的WCF Service方法编写
---------------------------------
公共UploadedFileInfo Upload(RemoteFileInfo remoteFileInfo)
{
字符串filePath = string.Empty;
试试
{
如果(remoteFileInfo.User!="Neena" || remoteFileInfo.Password!="123")
引发新的Exception(无效的用户或密码.");
uploadDirInitial = System.Configuration.ConfigurationManager.AppSettings ["FileUploadDirectory"];
uploadDirFinal = string.Concat(uploadDirInitial,remoteFileInfo.FilePath);
如果(!System.IO.Directory.Exists(uploadDirFinal))System.IO.Directory.CreateDirectory(uploadDirFinal);
filePath = System.IO.Path.Combine(uploadDirFinal,remoteFileInfo.FileName);
bool appendToFile = remoteFileInfo.AppendFlag == 1;
FileMode fileMode;
如果(!appendToFile)
{
如果(File.Exists(filePath))
File.Delete(filePath);
fileMode = FileMode.Create;
}
其他
{
fileMode = FileMode.Append;
}


//从输入流中读取字节
流stream =新的MemoryStream(remoteFileInfo.FileStream);
如果(remoteFileInfo.FileName!= string.Empty&& remoteFileInfo.FileStream.Length> 0)
{
使用(System.IO.FileStream writeStream = new System.IO.FileStream(filePath,fileMode,System.IO.FileAccess.Write))
{
byte []缓冲区=新的byte [remoteFileInfo.FileStream.Length];
int bytesRead = stream.Read(buffer,0,buffer.Length);

//将字节写入输出流
writeStream.Write(buffer,0,bytesRead);

writeStream.Close();
}
}
UploadedFileInfo.FileName = remoteFileInfo.FileName;
uploadFileInfo.FileSize = remoteFileInfo.FileStream.Length;
ParseUploadedFile(ref uploadedFileInfo);
}
catch(Exception exp)
{
uploadFileInfo.WcfException =服务异常:" + exp.Message.ToString();
}
返回uploadFileInfo;
}

------------------------------------------------
silverlight Upload.xaml文件
------------------------------------------------

if(bytesRemaining> CHUNK_SIZE)//可以在配置文件中更改CHUNK_SIZE
{
字节=新字节[CHUNK_SIZE];
FileStream.Read(bytes,0,CHUNK_SIZE);
remoteFile [i] .FileStream =字节;
}
else//其他文件流将仅包含剩余字节
{
字节=新的字节[bytesRemaining];
FileStream.Read(bytes,0,System.Convert.ToInt32(bytesRemaining));
remoteFile [i] .FileStream =字节;
}
如果(BytesUploaded [i] == 0)
{
remoteFile [i] .AppendFlag = 0; //不要追加
}
否则,如果(BytesUploaded [i]< BytesTotal [i])
{
remoteFile [i] .AppendFlag = 1; //附加
}
其他
{
返回; //上传完成
}
TransportService.TransportServiceClient客户端=新的ACR.Transport.Controls.TransportService.TransportServiceClient();
client.UploadCompleted + =新的EventHandler< ACR.Transport.Controls.TransportService.UploadCompletedEventArgs>(client_UploadCompleted);
client.UploadAsync(remoteFile [i]);
BytesUploaded [i] + = bytes.Length; //更新当前文件的字节上载计数器
UploadedFileSize + = bytes.Length; //到目前为止更新所有文件的字节上载计数器

任何帮助表示赞赏

谢谢
Thanks for the response

we have already tried increasing the buffer size

the maximum value it was taking was 60MB

but we need to upload files of size 1 to 3 GB

so we were using chunking the large file into chunks and then upload

but then it could upload the first file and failing to upload the next files

looks like the problem is with uploadasync method

but that is how it is supposed to upload multiple files

also our problem is that we can not debug the code

the silverlight application could send in chunks

the problem was that on WCF service how to handle writing the chunks to the correct file

I am pasting my code here

Web.config
--------------

< <system.web>
<httpRuntime maxRequestLength="2147483647"/>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true" targetFramework="4.0">
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<bindings>
<basicHttpBinding>
<binding name="TransportServiceBinding" maxBufferSize="2147483647" maxBufferPoolSize="5242880000"
maxReceivedMessageSize="2147483647" receiveTimeout="10:10:00" sendTimeout="10:10:00"
openTimeout="10:10:00" closeTimeout="10:10:00"
transferMode="StreamedResponse">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
----------------------------------------------------------
my WCF Service method to write
---------------------------------
public UploadedFileInfo Upload(RemoteFileInfo remoteFileInfo)
{
string filePath = string.Empty;
try
{
if (remoteFileInfo.User != "Neena" || remoteFileInfo.Password != "123")
throw new Exception("Invalid User or Password.");
uploadDirInitial = System.Configuration.ConfigurationManager.AppSettings["FileUploadDirectory"];
uploadDirFinal = string.Concat(uploadDirInitial, remoteFileInfo.FilePath);
if (!System.IO.Directory.Exists(uploadDirFinal)) System.IO.Directory.CreateDirectory(uploadDirFinal);
filePath = System.IO.Path.Combine(uploadDirFinal, remoteFileInfo.FileName);
bool appendToFile = remoteFileInfo.AppendFlag == 1;
FileMode fileMode;
if (!appendToFile)
{
if (File.Exists(filePath))
File.Delete(filePath);
fileMode = FileMode.Create;
}
else
{
fileMode = FileMode.Append;
}


// read bytes from input stream
Stream stream = new MemoryStream(remoteFileInfo.FileStream);
if (remoteFileInfo.FileName != string.Empty && remoteFileInfo.FileStream.Length > 0)
{
using (System.IO.FileStream writeStream = new System.IO.FileStream(filePath, fileMode, System.IO.FileAccess.Write))
{
byte[] buffer = new byte[remoteFileInfo.FileStream.Length];
int bytesRead = stream.Read(buffer, 0, buffer.Length);

// write bytes to output stream
writeStream.Write(buffer, 0, bytesRead);

writeStream.Close();
}
}
uploadedFileInfo.FileName = remoteFileInfo.FileName;
uploadedFileInfo.FileSize = remoteFileInfo.FileStream.Length;
ParseUploadedFile(ref uploadedFileInfo);
}
catch (Exception exp)
{
uploadedFileInfo.WcfException = "Exception from Service: " + exp.Message.ToString();
}
return uploadedFileInfo;
}

------------------------------------------------
silverlight Upload.xaml file
------------------------------------------------

if (bytesRemaining > CHUNK_SIZE) //CHUNK_SIZE can be changed in the configuration file
{
bytes = new byte[CHUNK_SIZE];
FileStream.Read(bytes, 0, CHUNK_SIZE);
remoteFile[i].FileStream = bytes;
}
else //Else filestream will contain only the remaining bytes
{
bytes = new byte[bytesRemaining];
FileStream.Read(bytes, 0, System.Convert.ToInt32(bytesRemaining));
remoteFile[i].FileStream = bytes;
}
if (BytesUploaded[i] == 0)
{
remoteFile[i].AppendFlag = 0; // Dont''t append
}
else if (BytesUploaded[i] < BytesTotal[i])
{
remoteFile[i].AppendFlag = 1; // append
}
else
{
return; // Upload finished
}
TransportService.TransportServiceClient client = new ACR.Transport.Controls.TransportService.TransportServiceClient();
client.UploadCompleted += new EventHandler<ACR.Transport.Controls.TransportService.UploadCompletedEventArgs>(client_UploadCompleted);
client.UploadAsync(remoteFile[i]);
BytesUploaded[i] += bytes.Length; // Update the Bytes uploaded counter for the current file
UploadedFileSize += bytes.Length; // Update the Bytes uploaded counter for all the files till now

any help is appreciated

Thanks


这篇关于上载&amp;使用Silverlight&amp;的多个文件世界足球联合会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆