Revalee icon indicating copy to clipboard operation
Revalee copied to clipboard

Unsuccessful callback to http://..... due to HTTP status code 401

Open abelmagana88920 opened this issue 9 years ago • 9 comments

Sir, I have been setup the revalee service in my computer and also I used MVC C# Appllication to send request to Revalee, but when I visit the logs of my computer, it shows Unable to callback to http://..... due to HTTP status code 401.

abelmagana88920 avatar Aug 26 '16 04:08 abelmagana88920

  1. Is the callback to an http: or an https: URL?
  2. What is the hostname and port of the MVC application? Is it running on the same computer as the Revalee Service?
  3. Does your local firewall/proxy software allow the Revalee Service to issue an outbound connection on that callback port?
  4. Does your MVC application accept anonymous (public) connections to the callback URL?
  5. Does your MVC controller action allow the POST method to the callback URL?

BrianMullin avatar Aug 26 '16 15:08 BrianMullin

tnx for the response.

this is my code where my mvc application calls Revalee service

   [AllowAnonymous]
    [HttpPost] 
    public JsonResult SendRequest(string customer_no)
    {


        JsonResult result;
        try
        {
            result = DataCSVXLS(customer_no);
            dynamic resultData = result.Data;
            string filePath = resultData.filePath;


           // Emails(customer_no, filePath);

           // FTPs(customer_no, filePath);

            return Json(result.Data, JsonRequestBehavior.AllowGet);
        }
        catch (Exception ex)
        {
            return Json(new { message = ex.Message });

        }
    }

public JsonResult RevaleeTest(string customer_no) {

        string revaleeServiceHost = "localhost:46200";
        try
        {
            //var TimeS=TimeSpan.FromSeconds(5.0);
            var TimeS = DateTimeOffset.Now.AddMinutes(0.25);
            Uri expirationMessageCallbackUri = new Uri(
                string.Format("http://localhost:65369/Customer/SendRequest/NIC105", customer_no));

            Guid expirationMessageCallbackId = RevaleeRegistrar.ScheduleCallback(
                revaleeServiceHost, TimeS, expirationMessageCallbackUri);

            return Json(new { message = TimeS }, JsonRequestBehavior.AllowGet);

        }
        catch (Exception e)
        {
            return Json(new {message = e.Message}, JsonRequestBehavior.AllowGet);
        }
    }

1.) Is the callback to an http: or an https: URL? The callback is call via http URL

2a.) What is the hostname and port of the MVC application? The hostname is localhost and the port is 65369 but I used this port in development (currently in Microsoft Visual Studio). also I deployed my MVC Application to IIS where the port I used is 92.

2.b) Is it running on the same computer as the Revalee Service? Yes. It is running in the same computer. I can see the Revalee Service in the Services and it is already started on local computer

3.) Does your local firewall/proxy software allow the Revalee Service to issue an outbound connection on that callback port?

How can I allow the Revalee Service to outbound connection?

4.) Does your MVC application accept anonymous (public) connections to the callback URL? Yes I used [AllowAnonymous] in mVC Application

5.) Does your MVC controller action allow the POST method to the callback URL? Yes I used [HttpPost] in mVC Application

abelmagana88920 avatar Aug 29 '16 10:08 abelmagana88920

i Set the outbound connection on the Revalee Service and allow the port 92 and 65369 but still 401 status displayed in the logs

abelmagana88920 avatar Aug 29 '16 10:08 abelmagana88920

  1. If you remove [HttpPost] from the SendRequest action temporarily and use your web browser to request http://localhost:65369/Customer/SendRequest/NIC105, then does the SendRequest action work properly?
  2. The Revalee Service is issuing the callback and needs to know if the callback was successful. Your callback action is returning a JsonResult. It needs to return an ActionResult. On success, the method should return a 200 OK HTTP result.
    return new HttpStatusCodeResult(HttpStatusCode.OK);

BrianMullin avatar Aug 29 '16 16:08 BrianMullin

1.) Yes, It works properly. 2.) I already modified the code, instead Public JsonResult RevaleeTest, I used Public ActionResult and return new HttpStatusCodeResult(HttpStatusCode.OK); but still 401 status displayed on the logs.

A few question Why do we need this code in web.config

<revalee>
    <clientSettings serviceBaseUri="http://localhost:46200" authorizationKey="add_your_secret_key_here_012345678901234567890123456789"/>
    <recurringTasks callbackBaseUri="http://localhost:65369">
      <task periodicity="daily" hour="00" minute="00" url="/RevaleeTest"/>
      <task periodicity="hourly" minute="30" url="/RevaleeTest"/>
    </recurringTasks>

  </revalee>

I dont understand why authorization key is required.

abelmagana88920 avatar Aug 29 '16 23:08 abelmagana88920

You assign a secret key so that you can ensure the callback action is only called by your pre-authorized callback requests.

Callback validation is automatically performed if you add the [CallbackAction] attribute to the callback method or use the following line programmatically:

if (!RevaleeRegistrar.ValidateCallback(this.Request))
{
...

BrianMullin avatar Aug 29 '16 23:08 BrianMullin

ok but why 401 status still displayed on the logs?

abelmagana88920 avatar Aug 29 '16 23:08 abelmagana88920

It is ok if I remove the revalee tag in the web.config?

abelmagana88920 avatar Aug 29 '16 23:08 abelmagana88920

You can remove the <revalee> tag from web.config, since you configured the required settings in your code. If you are not using recurring tasks, you should definitely not have that section in the web.config.

BrianMullin avatar Aug 30 '16 00:08 BrianMullin