I am using webclient to upload my files to server via Rest Service. I am checking my code by debugging it on a local host what I found is my server is successfully receiving all these files but at client end where I have a code for sending file I am getting this exception.
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: The remote server returned an error: (500) Internal Server Error."
The code I am using is below:
var Filereqparam = new System.Collections.Specialized.NameValueCollection();
using (var lWebClient = new WebClient()) {
foreach (var file in data.file) {
Filereqparam.Add("FileName", file.FileName);
Filereqparam.Add("FileExtension", file.FileExtension);
Filereqparam.Add("FileData", file.FileData);
System.Diagnostics.Debug.WriteLine( Filereqparam);
var recvFiledata = lWebClient.UploadValues("http://localhost:56156/api/userfiles/getfiles", Filereqparam);
var respFileBody = Encoding.UTF8.GetString(recvFiledata);
}
}
I have set the time limit for client to unlimited, but still I am unable to resolve this issue. My question is why I am receiving this exception if my files are successfully sent to server?
Note: If anyone know a better way to upload the large files to server via rest service then please share your technique.