none
Redis RRS feed

  • Question

  • Hi

    I m not getting response in web api while passing the request through uri.

    This is the exception i m getting

    "System.Threading.Tasks.TaskCanceledException: A task was canceled.\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at DPE.HolidayCalenderServices.Controllers.HolidayCalenderController.<GetHolidayCalenderAsync>d__2.MoveNext() in C:\\Users\\Juhi_Sharma\\Desktop\\doc\\DPE\\DPE.HolidayCalenderServices\\Controllers\\HolidayCalenderController.cs:line 34"

    this is the code:

    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Threading.Tasks;
    using DPE.HolidayCalenderProvider;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Mvc;



    namespace DPE.HolidayCalenderServices.Controllers
    {
        [Produces("application/json")]
        [Route("api/HolidayCalender")]



        public class HolidayCalenderController : Controller
        {
            private readonly IHolidayCalenderSrvProvider _calProvider;
            public HolidayCalenderController()
            {
                _calProvider = new HolidayCalenderSrvProvider();
            }
            [HttpGet]
            [Route("GetHolidays/{CountryCode}/{Fromdate}/{Todate}")]
           // public async Task<IActionResult> GetHolidayCalenderAsync(string CountryCode, string Fromdate, string Todate)
             public async Task<IActionResult> GetHolidayCalenderAsync([System.Web.Http.FromUri] HolidayDetails hd) // check equelent attribute for FromUri

            {
                try
                {
                    var res = await Task.Run(() => _calProvider.GetHolidayCalender(hd.CountryCode,hd.FromDate,hd.ToDate));//hd.countrycode.......
                    if (res != null)
                        return Ok(res);
                    else
                        return Ok("Order not found! Order Num:" + hd.CountryCode.ToString());//hd.countrycode
                }
                catch (Exception ex)
                {
                    return new JsonResult(ex.ToString());
                }
            }



            [HttpPost]
            [Route("SetHolidays/{countrycode}/{buId}/{date}/{isweekend}/{desc}")]
            public async Task<IActionResult> SetHolidayCalenderAsync(string countrycode, string buId, string date, bool isweekend, string desc)
              {
                try
                {
                    var holidayObject = new HolidayInfo
                    {
                        BuId =buId,
                        ContryCode = countrycode,
                        HolidayDate = DateTime.ParseExact(date, "MM/dd/yyyy",CultureInfo.InvariantCulture),
                        IsWeekend = true,
                        HolidayDescription = desc,
                        CreatedBy = Environment.UserName,
                        CreatedOn = DateTime.Now
                    };

                    var Key = countrycode + "_" + date.Replace('/', '_');

                    var res = await Task.Run(() => _calProvider.SetHolidayCalender(countrycode, holidayObject));
                    if (res)
                        return new JsonResult("Is a holiday:" + countrycode);
                    else
                        return new JsonResult("Error occured!:" + countrycode);
                }
                catch (Exception ex)
                {
                    return new JsonResult(ex.ToString());
                }
            }
        }
    }

    can anyone help me.

    thanks


    • Edited by juhi sharma Thursday, April 26, 2018 9:13 AM
    Thursday, April 26, 2018 7:58 AM

Answers

  • Hi juhi,

    What is your request URL? Do you access the web api from web browser?

    Based on this error message, it seems your issue is throw in Task.Run.

    To check whether there is something wrong while calling “_calProvider.GetHolidayCalender”. I suggest you try to make attest with code below, will you receive any error?

    var res = _calProvider.GetHolidayCalender(hd.CountryCode,hd.FromDate,hd.ToDate);//await Task.Run(() => _calProvider.GetHolidayCalender(hd.CountryCode,hd.FromDate,hd.ToDate));/

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by juhi sharma Monday, April 30, 2018 10:40 AM
    Friday, April 27, 2018 3:13 AM

All replies

  • Hi juhi,

    What is your request URL? Do you access the web api from web browser?

    Based on this error message, it seems your issue is throw in Task.Run.

    To check whether there is something wrong while calling “_calProvider.GetHolidayCalender”. I suggest you try to make attest with code below, will you receive any error?

    var res = _calProvider.GetHolidayCalender(hd.CountryCode,hd.FromDate,hd.ToDate);//await Task.Run(() => _calProvider.GetHolidayCalender(hd.CountryCode,hd.FromDate,hd.ToDate));/

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by juhi sharma Monday, April 30, 2018 10:40 AM
    Friday, April 27, 2018 3:13 AM
  • In this code i used a Var key  .How can i do search with that key in web Api.
    Monday, April 30, 2018 10:25 AM
  • how can i search to get the search response using this var key mentioned above in the code?

    can any one help me.

    thanku

    Monday, April 30, 2018 11:36 AM
  • if i am using this    var Key = countrycode + "_" + date.Replace('/', '_'); i am getting exception in post method while executing the code an testing it locally using postman .

    the exception that i got is

    "System.FormatException: String was not recognized as a valid DateTime.\r\n   at System.DateTime.ParseExact(String s, String format, IFormatProvider provider)\r\n   at DPE.HolidayCalenderServices.Controllers.HolidayCalenderController.<SetHolidayCalenderAsync>d__3.MoveNext() in C:\\Users\\Juhi_Sharma\\Desktop\\doc\\DPE\\DPE.HolidayCalenderServices\\Controllers\\HolidayCalenderController.cs:line 60"


    Monday, April 30, 2018 11:44 AM
  • Hi juhi,

    >>var Key = countrycode + "_" + date.Replace('/', '_'); i am getting exception in post method while executing the code an testing it locally using postman .

    This error is usually thrown when converting a string fail to date.

    For this new error, I would suggest you post a new thread, and share us the value for date.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 1, 2018 2:58 AM
  • But still i m not getting the search response .Can u tell me how to do search using key in web Api so that i can get the search response as per the request.

    and i also want to ask that in var res is showing null and at res id =60 and status is waiting for activation.

    Plz help me to solve this problem.


    Tuesday, May 1, 2018 8:26 AM
  • while sending the parameter through postman i am always getting false .Though i have used bool and checkmarked the box also in postman.

    anyone can help me

    thanks

    Tuesday, May 1, 2018 8:56 PM
  • >>Can u tell me how to do search using key in web Api so that i can get the search response as per the request.

    What do you mean by this?

    Could you share us more information about what you want to achieve?

    In addition, do you have any issue with thread below? If not, I would suggest you mark the helpful reply to close previous thread.

    https://social.msdn.microsoft.com/Forums/office/en-US/7816d64a-f0fb-4320-8cde-d45c1352993a/not-able-to-print-the-date-in-correct-format-from-an-excel-sheet?forum=vsto

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 2, 2018 7:01 AM