Asked by:
WCF Big File Upload Issues

General discussion
-
Hi All,
I have created a WCF service with basichttpbinding and its working fine up to 30Kb file but it’s not working for grater then 40Kb files.
WCF service Files are
WCF Config File
<system.web><compilation debug="true" targetFramework="4.0"/>
<httpRuntime maxRequestLength="2147483647" useFullyQualifiedRedirectUrl="true" executionTimeout="14400" />
<!-- App Setting for WCF Start -->
<appSettings>
<add key="UploadDir" value="C:\upload\"/>
</appSettings>
<!-- App Setting for WCF Start -->
<!-- WCF Configuration Start-->
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingSettings" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00"sendTimeout="04:01:00" maxBufferSize="2097151" allowCookies="True" maxReceivedMessageSize="2097151" maxBufferPoolSize="2097151" messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed">
<readerQuotas maxDepth="64" maxStringContentLength="2097151" maxArrayLength="2097151" maxBytesPerRead="4096" maxNameTableCharCount="2097151"/>
<security mode="None">
<transport clientCredentialType="None"/>
ITransferService.cs file[ServiceContract]
public interface ITransferService
{
[OperationContract ][WebInvoke( Method = "POST")]
void UploadFile(RemoteFileInfo request);
}[MessageContract]
public class DownloadRequest
{
[MessageBodyMember]
public string FileName;
}
[MessageContract]public class RemoteFileInfo : IDisposable
{
[MessageHeader(MustUnderstand = true)]
public string FileName;
[MessageHeader(MustUnderstand = true)]public long Length;
[MessageBodyMember(Order = 1)]public System.IO.Stream FileByteStream;
public void Dispose(){
if (FileByteStream != null)
{
FileByteStream.Close();
FileByteStream = null;
}
}
}
TransferService.cs
// Service Started ....
public class TransferService : ITransferService
{
public void UploadFile(RemoteFileInfo request)
{
FileStream targetStream = null;
Stream sourceStream = request.FileByteStream;
try
{
//string uploadFolder = @"C:\upload\";
string uploadFolder = ConfigurationManager.AppSettings["UploadDir"].ToString();
string DatetimeStamp = String.Format("{0:yyyy-MM-dd_hh-mm-ss}", DateTime.Now);
string strFileName = DatetimeStamp + "_" + request.FileName;
//string strFileName = "Test.txt";
string filePath = Path.Combine(uploadFolder, strFileName);
using (targetStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None)){
const int bufferLen = 65000;
byte[] buffer = new byte[bufferLen];
int count = 0;
while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)
{
// save to output stream
targetStream.Write(buffer, 0, count);
}
targetStream.Close();
sourceStream.Close();
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
}}
Client Files are as followings Default.aspx.cs (this file having one file browses and submit button )
public partial class _Default : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e)
{
}protected void Upload_Click(object sender, EventArgs e)
{
if (FileUpload.HasFile)
{
System.IO.FileInfo fileInfo = new System.IO.FileInfo(FileUpload.PostedFile.FileName);
FileTransferServiceReference.ITransferService clientUpload = new FileTransferServiceReference.TransferServiceClient();
FileTransferServiceReference.RemoteFileInfo
uploadRequestInfo = new RemoteFileInfo();
string DatetimeStamp = DateTime.Now.ToString();
string strFileName = DatetimeStamp + "_" + FileUpload.PostedFile.FileName;
using (System.IO.FileStream stream = new System.IO.FileStream(FileUpload.PostedFile.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
uploadRequestInfo.FileName = FileUpload.FileName;
uploadRequestInfo.Length = fileInfo.Length;
uploadRequestInfo.FileByteStream = stream;
clientUpload.UploadFile(uploadRequestInfo);
//Response.Write("File Sussfully Uploaded");
ConLable.Text = "File Sussfully Uploaded";
//clientUpload.UploadFile(stream);}
}
}
}
Web Config.<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITransferService" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00"
sendTimeout="04:01:00" allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8"
transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="128"
maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
</client>
</system.serviceModel>
</configuration>
Please could you let me know where I am making any mistake …when I am changing transferMode="Buffered" to Streamed in Client its not uploading any files.
Please help I will appreciate responsesFriday, May 3, 2013 7:29 AM
All replies
-
Hi,
To get actual cause of this issue, you need enable tracing for your service and you can analyze the diagnostic traces with the help of SvcTraceViewer.exe tool.
http://msdn.microsoft.com/en-us/library/ms733025.aspx
Best Regards.
Haixia
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Tuesday, May 7, 2013 2:15 AM