Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Norman Lynch 5 posts 86 karma points
    Jul 23, 2015 @ 19:17
    Norman Lynch
    0

    Umbraco 7 Scheduled Task

    I'm trying to set up a scheduled task, but I think I must be missing some key concept. Here's what I've got so far.

    In umbracoSettings.config, I've got the following:

      <scheduledTasks>
        <task log="true" alias="import-from-blogs" interval="60" url="http://localhost:49244/Umbraco/Api/BlogApi/Import" />
      </scheduledTasks>
    

    Then, I've created an API Controller:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Umbraco.Web.WebApi;
    
    namespace psclistens.Controllers
    {
        public class BlogApiController : UmbracoApiController
        {
            public String Import()
            {
                return "foo";
            }
        }
    }
    

    When run Umbraco, I see this in the UmbracoTraceLog.txt file:

    System.Net.ProtocolViolationException: Cannot send a content-body with this verb-type.
       at System.Net.HttpWebRequest.CheckProtocol(Boolean onRequestStream)
       at System.Net.HttpWebRequest.BeginGetRequestStream(AsyncCallback callback, Object state)
       at System.Net.Http.HttpClientHandler.StartGettingRequestStream(RequestState state)
       at System.Net.Http.HttpClientHandler.PrepareAndStartContentUpload(RequestState state)
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Umbraco.Web.Scheduling.ScheduledTasks.<GetTaskByHttpAync>d__9.MoveNext()
    2015-07-23 14:14:19,440 [6] INFO  Umbraco.Web.Scheduling.ScheduledTasks - [P2876/T1/D2] import-from-blogs has been called with response: False
    

    Any hints or suggestions would be appreciated.

    -- Norman Lynch

  • Norman Lynch 5 posts 86 karma points
    Jul 28, 2015 @ 15:25
    Norman Lynch
    0

    I've tried a bunch of different stuff and I always get the same error. I'm beginning to suspect that scheduled tasks are broken in Umbraco 7. Can anyone confirm or deny this?

    -- Norman Lynch

  • Andrew Ellis-chadwick 4 posts 114 karma points
    Aug 09, 2015 @ 17:51
    Andrew Ellis-chadwick
    0

    Have you tried the [AcceptVerbs("GET")] attribute in your api controller?

  • René Pjengaard 118 posts 702 karma points c-trib
    Aug 10, 2015 @ 07:29
    René Pjengaard
    2

    Hi,

    i think Andrew is right. Try to add [HttpGet] to your method:

    namespace psclistens.Controllers {
    
    [System.Web.Http.HttpGet]
    public class BlogApiController : UmbracoApiController
    {
        public String Import()
        {
            return "foo";
        }
    }
    

    }

    If it still won´t work, try call a normal url from the taskmanager, to check if it is broken or you have a problem in your api.

    Best regards René

  • Sanjay Sen 33 posts 97 karma points
    Sep 28, 2015 @ 07:17
    Sanjay Sen
    0

    Hi,

    I have tried above fix by adding "[System.Web.Http.HttpGet]" to API controller but it is still not working. Please suggest.

    Thanks

  • Hywel Rees 56 posts 224 karma points
    Sep 28, 2015 @ 14:23
    Hywel Rees
    0

    Not sure if that was a typo on René's post - the [HttpGet] decorator needs to go above the method, not the class.

    namespace psclistens.Controllers 
    {
        public class BlogApiController : UmbracoApiController
        {
            [System.Web.Http.HttpGet]
            public String Import()
            {
                return "foo";
            }
        }
    

    I don't know if this will fix your issue though.

  • René Pjengaard 118 posts 702 karma points c-trib
    Sep 28, 2015 @ 14:33
    René Pjengaard
    0

    Sorry, my mistake. Thank you Hywel!

    @Sanjay, have you tried calling a normal url from scheduletask?

    /R

  • Sanjay Sen 33 posts 97 karma points
    Sep 29, 2015 @ 08:59
    Sanjay Sen
    0

    Hi Hywel,

    Sorry my bad when I said on controller. I did try this above on method not controller but it didn't work. I am able to call the url in browser and it does work and perform the required task which proves the url is working fine. Also I tried a different url also which doesn't do anything but that is also not working and giving the same error

    ================ 2015-09-29 14:24:55,369 [135] ERROR Umbraco.Web.Scheduling.ScheduledTasks - [P6844/T104/D3] An error occurred calling web task for url: http://localhost:8080/enjoy System.Net.ProtocolViolationException: Cannot send a content-body with this verb-type.

    ===========================

    I have seen some post where its said it is fixed in 7.3.0 RC but I want to stay of 7.2.8 version and want a fix. Please suggest.

    Thanks Sanjay

  • René Pjengaard 118 posts 702 karma points c-trib
    Sep 29, 2015 @ 10:43
    René Pjengaard
    0

    Hi Sanjay,

    do you have an Access-Control-Allow-Origin in your method? Maybe that could make it work.

    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");

    Best René

  • Sanjay Sen 33 posts 97 karma points
    Nov 09, 2015 @ 11:58
    Sanjay Sen
    0

    Hi Rene,

    Thanks for your reply but no luck with HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");

    Do you think you can suggest something else to make it work please?

    Thanks Sanjay

  • Naveed Ali 161 posts 426 karma points
    Aug 05, 2016 @ 13:08
    Naveed Ali
    0

    was this ever resolved I am getting the same error trying to run a scheduled task:

    Umbraco.Web.Scheduling.ScheduledTasks - [P65892/T209/D11] reminderEmails has been called with response: False

    Thanks

    Nav

  • Paul de Quant 403 posts 1520 karma points
    Jul 28, 2017 @ 14:47
    Paul de Quant
    0

    Hi Naveed,

    I'm getting the same issue as you, did you find a fix in the end?

    Thanks

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft