Unsuccessful callback to http://..... due to HTTP status code 401
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.
- Is the callback to an http: or an https: URL?
- What is the hostname and port of the MVC application? Is it running on the same computer as the Revalee Service?
- Does your local firewall/proxy software allow the Revalee Service to issue an outbound connection on that callback port?
- Does your MVC application accept anonymous (public) connections to the callback URL?
- Does your MVC controller action allow the POST method to the callback URL?
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
i Set the outbound connection on the Revalee Service and allow the port 92 and 65369 but still 401 status displayed in the logs
- 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?
- 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);
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.
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))
{
...
ok but why 401 status still displayed on the logs?
It is ok if I remove the revalee tag in the web.config?
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.