I am trying to send a conversation message, I able to receive the message but I didn't get the report, I configured reportUrl, but the report doesn't arrive, why?
I checked into /var/www/apache2/access.log, I got below:
35.246.41.39 - - [01/Jun/2021:11:24:44 +0000] "POST /whatsapp/myWebhookAsync? HTTP/1.1" 200 5327 "-" "MessageBirdHTTPQueue/1622459790-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
my webhook is only simple, I just want to log it into a file, just want to make sure if it really arrives or not
[HttpPost]
[Route("/WhatsApp/myWebhookAsync")]
[AllowAnonymous]
public async Task myWebhookAsync()
{
using (var reader = new StreamReader(Request.Body))
{
string _jsonx = await reader.ReadToEndAsync();
await Helper.SaveLogAsync("CAPTURED --- WhatsAppController.MessageBird_ReportAsync " + _jsonx);
}
}
Related
i am trying to call web Api that returns a list of object but it always throws an error : Internal Server Error
my code as below:
Web API
// GET: api/UploadFileStructures
[ResponseType(typeof( IEnumerable<UploadFileStructure>))]
public IHttpActionResult GetUploadFileStructuresByMovieId(int MovieDetailId)
{
IEnumerable<UploadFileStructure> uploaFileStructures= db.UploadFileStructures.Where(u=>u.MovieDetailId== MovieDetailId).AsEnumerable();
return Ok(uploaFileStructures);
}
Http Request:
using (var client = new HttpClient(handler))
{
//client.BaseAddress = UsersLogin;
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = client.GetAsync(String.Format(GetUploadFileStructuresByMovieIdUrl, MovieDetailId)).Result;
if (response.IsSuccessStatusCode)
{
UploadFileStructureDtls= response.Content.ReadAsAsync<IQueryable<UploadFileStructure>>().Result;
}
}
response.IsSuccessStatusCode is returing false and response returning " Internal Server Error"
The problem is on this line of your server code:
IEnumerable<UploadFileStructure> uploaFileStructures= db.UploadFileStructures.Where(u=>u.MovieDetailId== MovieDetailId).AsEnumerable();
If you set a breakpoint there, you should be able to see the actual error message that is generated.
I have a standard Ajax call with "Success" and "error". The error part is as straightforward as:
error: function (xMlHttpRequest, textStatus, errorThrown) {
errorLabel.text("ERROR: " + xMlHttpRequest.responseText); },
And in my C# backend, I saw someone recommend to use these code:
Response.StatusCode = 409; //as long as not 200
Response.Clear();
Response.Write(msg);
Response.End();
My errorLabel successfully display xMlHttpRequest.responseText after validation ON MY LOCAL DEV MACHINE.
However when I publish everything to a WINDOWS 2012 SERVER, there is no customized 'msg' in xMlHttpRequest.responseText anymore. Instead I got "The page was not displayed because there was a conflict" in responseText. (I could understand that status code 409 means there is a conflict.)
So how come it will perform like that when on a server ?? My own error message seems to have been replaced!
Thanks a lot!
*********************** C# Code ******************
[HttpPost]
public ActionResult DoSomething()
{
if (someconditiontrue)
{
return Json(new {value1=xxxx, value2=yyy})
}
else
{
Response.StatusCode = 409; //as long as not 200
Response.Clear();
Response.Write("my customized error message");
Response.End();
}
return Content(string.Empty);
}
I worked it around by not using "error" as returned result. Instead I still use Json { error = "my customized error message") object as result, and display corresponding validation message in "success: function(result){....}" block.
private async Task Run()
{
//setting up OAuth 2.0 authentication
ClientSecrets secret = new ClientSecrets
{
ClientId = <My ID Here>,
ClientSecret = <My Secret Here>
};
UserCredential credentials = await GoogleWebAuthorizationBroker.AuthorizeAsync(secret, new[] { Scope }, "user", CancellationToken.None);
//create the service
service = new DoubleclicksearchService(new BaseClientService.Initializer()
{
HttpClientInitializer = credentials,
ApplicationName = <My Application Name Here>
});
//make request to download keywords; response variable will hold Id of generated report
Report response = await service.Reports.Request(CreateRequestBody()).ExecuteAsync();
Console.WriteLine("Created Report: ID={0}", response.Id);
}
First time user of the DoubleClick Search API. The above code is my snippet attempting to make a keyword report request. Each run however, the service.Reports.Request line throws an exception. Specifically the error is:
"Google.Apis.Requests.RequestError\r\nForbidden [403]\r\nErrors [\r\n\tMessage[Forbidden] Location[ - ] Reason[forbidden] Domain[global]\r\n]\r\n"
Any ideas what's going on here? If I make the call without the ExecuteAsync() part it works fine, but then I can't get at the Id of the submitted report.
For those interested, it appears ExecuteAsync was the wrong method to use here. The retrieval of the Report object that contains the ID of the report being generated is not created asynchronously, I believe. When I changed the last bit of code to
//make request to download keywords; response variable will hold Id of report to be generated
var request = service.Reports.Request(CreateRequestBody());
response = request.Execute();
Console.WriteLine("Report being generated. Report ID: {0}", response.Id);
it worked as expected.
I have an async action, which is supposed to return a JSON message to the browser after awaiting some task. Though the ActionResult is built and executed successfully(I'm using my own JsonResult, so I confirmed this by stepping into the source), the browser still gets no response(confirmed by Fiddler).
Meanwhile, it works if I'm awaiting for Task.Delay(), and returning a dummy message.
Strangely, if I rebuild my projects with VS2013 while the IIS Express running my website, all the sudden the browser receives the message that was supposed to be sent several minutes ago! I think it's shutting down the web server makes this happen, however I can't figure out how exactly this is happening.
I've been debugging for a day, disabled everything that I thought could have been related, with no luck. So any help about what could be the cause to this strange behavior is welcome. Thanks, here is the code:
[HttpPost]
public async Task<JsonResult> Update(string token)
{
try
{
//This works
//await Task.Delay(TimeSpan.FromSeconds(1));
//return Json(new { error = "testing." });
//This won't work
var feedback = await ServerConnectionKeeper.UpdateStation(token);
return feedback.Success
? Json(new { redirect = Url.Action("Index", "Home") })
: Json(new { error = feedback.Error });
}
catch (Exception ex)
{
return Json(new { error = ex.Message });
}
}
It turns out that I called an async void method, which made some strange unknown(by me) things happen. Here is the some conceptual code:
[HttpPost]
public async Task<JsonResult> Data()
{
await SomeTask();
return Json(new { message = "Testing" });
}
private async Task SomeTask()
{
FireAndForget();
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
}
private async void FireAndForget()
{
await Task.Delay(TimeSpan.FromSeconds(100)).ConfigureAwait(false);
}
With above code, I thought the response would come 1 second after requesting. But it does not, not even 100 seconds after. In some cases I get a InvalidOperationException, in other cases I get nothing.
If I change the async void to async Task, either ConfigureAwait(false) or not, every thing works:
[HttpPost]
public async Task<JsonResult> Data()
{
await SomeTask();
return Json(new { message = "Testing 4" });
}
private async Task SomeTask()
{
FireAndForget();
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
}
private async Task FireAndForget()
{
await Task.Delay(TimeSpan.FromSeconds(100)).ConfigureAwait(false);
}
The reason responses are sent when web server shutting down in my production code, is because my FireAndForget() method there is an async loop reading network messages, and never returns untill the connection closed, and shutting down the web server closes the connection. It's still strange to me that I didn't get InvalidOperationException there though.
In logica smpp I need to stored response message ID in asynchronous mode.
if (sb.asynchronous)
{
System.out.println("Submit request " + request.debugString());
sb.getSession().submit(request);
//messageId = response.getMessageId();
} else {
response = sb.getSession().submit(request);
messageId = response.getMessageId().trim();
}
In the above code. How we can get messageID in asynchronous mode.
You can get Message id by getSmDefaultMsgId() by calling it with SubmitSM 's object . like below:
if (sb.asynchronous)
{
System.out.println("Submit request " + request.debugString());
sb.getSession().submit(request);
messageId = request.getSmDefaultMsgId();
}
For more documentation you can read this tutorial
Thanks. Let me know if it helped.