My web service was working fine. When a file is larger than 2MB, it throws System.AggregateException in System.Private.CoreLib.dll.
can you give me some suggestion?
Below is the exception:
Exception thrown: 'System.AggregateException' in System.Private.CoreLib.dll An unhandled exception of type 'System.AggregateException' occurred in System.Private.CoreLib.dll One or more errors occurred.
System.AggregateException HResult=0x80131500 Message=One or more errors occurred. (The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.) Source=System.Private.CoreLib StackTrace: at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at sharepoint.Program.Main(String[] args) in C:\Users\Qihong.Kuang\source\repos\WebService\sharepoint\Program.cs:line 11
Inner Exception 1: FaultException: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.
static void Main(string[] args)
{
Console.WriteLine("Uploading...");
ServiceReference1.ServiceClient ws = new ServiceReference1.ServiceClient();
//something happened in this Async task;
ws.start_processAsync().Wait();
Console.WriteLine("Upload Finished!");
}
public class Service : IService
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
public void start_process()
{
WebService ws = new WebService();
ws.GetCredentials();
}
}
public class WebService : System.Web.Services.WebService
{
OracleConnection con;
List<int> file_ids = new List<int>();
int file_id2;
string queryString;
OracleCommand cmd;
OracleDataReader dtr;
byte[] g_file = new byte[0];
string file_name;
ClientContext ctx;
public WebService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
public void StartProcess()
{
var startTimeSpan = TimeSpan.Zero;
var periodTimeSpan = TimeSpan.FromSeconds(30);
var timer = new System.Threading.Timer((e) =>
{
GetCredentials();
}, null, startTimeSpan, periodTimeSpan);
}
public void GetCredentials()
{
var siteUrl = "siteURL";
var user = "USER";
var password = "PASSWORD";
var pwd = new SecureString();
string docLib = "testtest";
foreach (var c in password) pwd.AppendChar(c);
var SPOCredentials = new SharePointOnlineCredentials(user, pwd);
var SPCredentials = new NetworkCredential(user, pwd);
string subfolderPath = GetSubFolder();
file_ids = GetFileID();
//string uploadLocation = GetFileName();
foreach (var file_id in file_ids)
{
file_id2 = file_id;
ExecuteType("file_name");
string uploadLocation = file_name;
using (ctx = new ClientContext(siteUrl))
{
try
{
ctx.Credentials = SPOCredentials;
ctx.ExecuteQuery();
}
catch (ClientRequestException)
{
ctx.Credentials = SPCredentials;
ctx.ExecuteQuery();
}
catch (NotSupportedException)
{
ctx.Credentials = SPCredentials;
ctx.ExecuteQuery();
Console.WriteLine("SharePoint On-Premise");
}
var library = ctx.Web.Lists.GetByTitle(docLib);
var fileBytes = new byte[] { };
//fileBytes = ReadData();
ExecuteType("blob");
FileStream fileStream;
fileBytes = g_file;
//fileStream = new FileStream(g_file, FileMode.Open);
var fileCreationInformation = new FileCreationInformation();
uploadLocation = string.Format("{0}/{1}", subfolderPath, uploadLocation);
uploadLocation = string.Format("{0}/{1}/{2}", siteUrl, docLib, uploadLocation);
fileCreationInformation.Content = fileBytes;
fileCreationInformation.Overwrite = true;
fileCreationInformation.Url = uploadLocation;
//Upload the file to root folder of the Document library
library.RootFolder.Files.Add(fileCreationInformation);
ctx.ExecuteQuery();
DeleteRecordAfterUploadToSharePoint();
}
}
}
public void ExecuteType(string executeType)
{
con = new OracleConnection(GetConnectionString());
queryString = GetQueryString();
try
{
con.Open();
OracleCommand cmd = new OracleCommand(queryString, con);
dtr = cmd.ExecuteReader();
while (dtr.Read())
{
if (executeType == "file_name")
{
file_name = Convert.ToString(dtr["file_name"]);
}
else if (executeType == "blob")
{
g_file = (byte[])dtr["actual_file"];
}
}
}
catch (Exception ex)
{
string showError = "Error: " + ex.Message;
}
finally
{
dtr.Close();
con.Close();
}
}
public void DeleteRecordAfterUploadToSharePoint()
{
con = new OracleConnection(GetConnectionString());
string queryString = GetDeleteQueryString();
try
{
con.Open();
cmd = new OracleCommand(queryString, con);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
string showError = "Error: " + ex.Message;
}
finally
{
con.Close();
}
}
public List<int> GetFileID()
{
con = new OracleConnection(GetConnectionString());
string queryString = "select count(file_id), file_id from nfirs.sharepoint_file group by file_id";
OracleDataReader dtr = null;
try
{
con.Open();
OracleCommand cmd = new OracleCommand(queryString, con);
dtr = cmd.ExecuteReader();
while (dtr.Read())
{
file_ids.Add(Convert.ToInt32(dtr["file_id"]));
}
}
catch (Exception ex)
{
string showError = "Error: " + ex.Message;
}
finally
{
dtr.Close();
con.Close();
}
Console.WriteLine(file_ids);
return file_ids;
}
public int GetIndividualFileID()
{
return file_id2;
}
public string GetSubFolder()
{
DateTime dt = Convert.ToDateTime(DateTime.Now);
string year = dt.Year.ToString();
return year;
}
public string GetConnectionString()
{
return "Data Source=(DESCRIPTION =(connectionStringhere)";
}
public string GetQueryString()
{
return "select file_id, file_type, actual_file, file_name, file_mimetype, file_update_dttm, file_charset from nfirs.Sharepoint_File where file_id = " + GetIndividualFileID();
}
public string GetDeleteQueryString()
{
string deleteQuery = "delete from (" + GetQueryString() + ")";
return deleteQuery;
}
public string GetFileName()
{
con = new OracleConnection(GetConnectionString());
queryString = GetQueryString();
//OracleDataReader dtr = null;
//string file_name = "";
try
{
con.Open();
OracleCommand cmd = new OracleCommand(queryString, con);
dtr = cmd.ExecuteReader();
while (dtr.Read())
{
file_name = Convert.ToString(dtr["file_name"]);
}
}
catch (Exception ex)
{
string showError = "Error: " + ex.Message;
}
finally
{
dtr.Close();
con.Close();
}
return file_name;
}
public byte[] ReadData()
{
//OracleConnection con = new OracleConnection(GetConnectionString());
//List<int> file_ids = GetFileID();
//foreach(var file_id in file_ids)
//{
//}
string queryString = GetQueryString();
//OracleDataReader dtr = null;
//byte[] g_file = new byte[0];
try
{
con.Open();
cmd = new OracleCommand(queryString, con);
dtr = cmd.ExecuteReader();
while (dtr.Read())
{
g_file = (byte[])dtr["actual_file"];
}
}
catch (Exception ex)
{
string showError = "Error: " + ex.Message;
}
finally
{
dtr.Close();
con.Close();
}
return g_file;
}
}