hi,
I am calling this function via url from my desktop application
[HttpPost]
[AcceptVerbs("POST")]
async public Task<HttpResponseMessage> SyncItem(long TenantId)
{
try
{
CashVitae_TM.Tenant oTenant = new CashVitae_TM.Tenant();
oTenant = oTenant.getTenantByTenantId(TenantId);
string dbUN = oTenant.DBUN;
string dbPass = oTenant.DBPass;
long SavedItemId = 0;
Item oitem = new Item();
byte[] data = await Request.Content.ReadAsByteArrayAsync();
string JsonInventory = System.Text.Encoding.Default.GetString(data);
List<InventoryItem> lstInventoryItem = JsonConvert.DeserializeObject<List<InventoryItem>>(JsonInventory);
foreach (var Inventory in lstInventoryItem)
{
Item oitem1 = new Item();
string ItemCode = Inventory.ItemCode;
Item item = oitem.getItembyCode(TenantId, dbUN, dbPass, ItemCode);
if (item != null)
{
oitem1.Id = item.Id;
oitem1.Code = item.Code;
oitem1.CreatedDtTm = item.CreatedDtTm;
}
else
{
oitem1.Id = 0;
oitem1.Code = Inventory.ItemCode;
oitem1.CreatedDtTm = DateTime.Now;
}
oitem1.TenantId = TenantId;
oitem1.Name = Inventory.Name;
oitem1.Category = Convert.ToString(Inventory.Category);
oitem1.CostMethod = Convert.ToString(Inventory.MethodName);
oitem1.Location = Convert.ToString(Inventory.Location);
oitem1.UnitPrice = Inventory.UnitPrice;
oitem1.Quantity = Inventory.QtyAvailable;
oitem1.QtyOnHand = Inventory.QtyOnHand;
oitem1.IsActive = Inventory.IsActive;
oitem1.ModifiedDtTm = DateTime.Now;
SavedItemId = oitem1.Save(TenantId, dbUN, dbPass);
}
return new HttpResponseMessage(HttpStatusCode.OK);
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
and this my desktop application code
try
{
string str = Inventory();
using (WebClient httpclient = new WebClient())
{
string url = "http://localhost:51411/api/MobileAPI/SyncItem?TenantId=" + CommonClass.tenantId;
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(str);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "Post";
request.ContentLength = data.Length;
request.ContentType = "application/json";
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
request.Timeout = Timeout.Infinite;
request.KeepAlive = true;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.StatusCode.ToString();
}
}
catch(Exception ex)
{
throw ex;
}
but i am getting operation has timeout exception in my desktop
What I have tried:
I am calling a method in my API to save data in web DB
I tried
request.Timeout = Timeout.Infinite;
request.KeepAlive = true;
then also same error i am getting, how i can handle timeout exception.
one solution I know that split data but if anyone can give else solution without split data, only once i want to send whole data.