Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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.
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900