I am working on upload and download files using wcf.I am able download large files .But I am able to upload only small files. Here is my code
 
Server Config File 
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
hostNameComparisonMode="StrongWildcard" >
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
 
Client web.config
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
hostNameComparisonMode="StrongWildcard" >
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
 
Server .cs File
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Search;
using Microsoft.SharePoint.Client.Search.Query;
using System.IO;
using System.Collections;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using System.Data;
using System.ComponentModel;
using Microsoft.Office.Server.Search.Query;
using System.Net;
using Microsoft.SharePoint.Search.Query;
using Microsoft.SharePoint.Client.Taxonomy;
using System.Web.Configuration;
namespace NewWCFServiceChange
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class Service1 : IService1
{
public string StrClientFileName = "";
public void UploadAFile(string filename, string strFilePath, string strAutoNUmber, string strmetadata, string strMetadataTags,string filePathcombine)
{
string Concat = "ORDID";
string strTAGS = "";
int Number = 0;
string Numbersplit = "";
using (ClientContext ctx = new ClientContext("http://machinename/sites/First"))
{
Web web = ctx.Web;
List uploadList = ctx.Web.Lists.GetByTitle("UploadList");
ctx.Load(uploadList);
ctx.ExecuteQuery();
strTAGS = hiddencreateterms(strMetadataTags);
int listCount = uploadList.ItemCount;
ListItemCreationInformation listCreationInformation = new ListItemCreationInformation();
ListItem oListItem = uploadList.AddItem(listCreationInformation);
oListItem["Title"] = filename;
oListItem["Docid"] = Number;
oListItem["DocPath"] = strFilePath;
oListItem["DownID"] = listCount+1;
oListItem["TaxKeyword"] = strTAGS;
oListItem["Metadataadd"] = strmetadata;
oListItem["OrderID"] = strAutoNUmber;
oListItem.Update();
ctx.ExecuteQuery();
}
}
 
Server Interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Microsoft.SharePoint.Client;
using System.IO;
using System.Collections;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using System.Data;
using System.ComponentModel;
using Microsoft.Office.Server.Search.Query;
using System.ServiceModel;
namespace NewWCFServiceChange
{
[ServiceContract]
public interface IService1
{
[OperationContract]
void UploadAFile(string filename, string strFilePath, string strAutoNUmber, string MetataData, string strMetadataTags,string filePathcombine);
[OperationContract]
void UploadFileAsPackets(RemoteFileInfo request);
[OperationContract]
RemoteFileInfoForDownload DownloadFileAsPackets(DownloadRequest request);
}
[MessageContract]
public class DownloadRequest
{
[MessageBodyMember]
public string FileName;
}
[MessageContract]
public class RemoteFileInfoForDownload
{
[MessageHeader(MustUnderstand = true)]
public string FileName;
[MessageHeader(MustUnderstand = true)]
public long Length;
[MessageBodyMember(Order = 1)]
public System.IO.Stream FileByteStream;
}
[MessageContract]
public class RemoteFileInfo : IDisposable
{
[MessageHeader(MustUnderstand = true)]
public string FileName;
[MessageHeader(MustUnderstand = true)]
public long Length;
[MessageHeader(MustUnderstand = true)]
public string strOrderID;
[MessageHeader(MustUnderstand = true)]
public string strmetadata;
[MessageHeader(MustUnderstand = true)]
public string strMetadataTags;
[MessageHeader(MustUnderstand = true)]
public string strDocPath;
[MessageBodyMember(Order = 1)]
public System.IO.Stream FileByteStream;
public void Dispose()
{
if (FileByteStream != null)
{
FileByteStream.Close();
FileByteStream = null;
}
}
}
}
Client .CS File
public void UploadFileAsPackets(RemoteFileInfo request)
{
// create output folder, if does not exist
if (!System.IO.Directory.Exists(@"c:\uploadedfiles")) System.IO.Directory.CreateDirectory(@"c:\uploadedfiles");
// kill target file, if already exists
//string filePath = System.IO.Path.Combine("Upload", request.FileName);
string filePath = @"\\MachineName\uploadedfiles\" + request.FileName;// ; System.IO.Path.Combine("Upload", request.FileName);
if (System.IO.File.Exists(filePath)) System.IO.File.Delete(filePath);
int chunkSize = 2048;
byte[] buffer = new byte[chunkSize];
using (System.IO.FileStream writeStream = new System.IO.FileStream(filePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write))
{
do
{
// read bytes from input stream
int bytesRead = request.FileByteStream.Read(buffer, 0, chunkSize);
if (bytesRead == 0) break;
// write bytes to output stream
writeStream.Write(buffer, 0, bytesRead);
} while (true);
writeStream.Close();
}
string filePathcombine = filePath;
string strmetadata= request.strmetadata;
string strMetadataTags=request.strMetadataTags;
string strOrderID=request.strOrderID;
UploadAFile(request.FileName, filePathcombine, strOrderID, strmetadata, strMetadataTags,filePathcombine);
}
public RemoteFileInfoForDownload DownloadFileAsPackets(DownloadRequest request)
{
// get some info about the input file
string filePath = @"\\Machinename\uploadedfiles\"+request.FileName;
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
// check if exists
if (!fileInfo.Exists) throw new System.IO.FileNotFoundException("File not found", request.FileName);
// open stream
System.IO.FileStream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
// return result
RemoteFileInfoForDownload result = new RemoteFileInfoForDownload();
result.FileName = request.FileName;
result.Length = fileInfo.Length;
result.FileByteStream = stream;
return result;
}
}
}
 
 
Client Side Reference File
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.IO;
using System.Collections;
using System.Data;
using System.ComponentModel;
namespace NewWCFClient
{
public class StreamWithProgress : Stream
{
private readonly FileStream file;
private readonly long length;
public class ProgressChangedEventArgs : EventArgs
{
public long BytesRead;
public long Length;
public ProgressChangedEventArgs(long BytesRead, long Length)
{
this.BytesRead = BytesRead;
this.Length = Length;
}
}
public event EventHandler ProgressChanged;
private long bytesRead;
public StreamWithProgress(System.IO.FileStream file)
{
this.file = file;
length = file.Length;
bytesRead = 0;
if (ProgressChanged != null) ProgressChanged(this, new ProgressChangedEventArgs(bytesRead, length));
}
public double GetProgress()
{
return ((double)bytesRead) / file.Length;
}
public override bool CanRead
{
get { return true; }
}
public override bool CanSeek
{
get { return false; }
}
public override bool CanWrite
{
get { return false; }
}
public override void Flush() { }
public override long Length
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override long Position
{
get { return bytesRead; }
set { throw new Exception("The method or operation is not implemented."); }
}
public override int Read(byte[] buffer, int offset, int count)
{
int result = file.Read(buffer, offset, count);
bytesRead += result;
if (ProgressChanged != null) ProgressChanged(this, new ProgressChangedEventArgs(bytesRead, length));
return result;
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new Exception("The method or operation is not implemented.");
}
public override void SetLength(long value)
{
throw new Exception("The method or operation is not implemented.");
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new Exception("The method or operation is not implemented.");
}
}
}
 
I need help on this.
 
Thanks
KK