How to create web hosting in ASP.NET MVC?

I am trying to create a simple web check to receive a delivery receipt from the Nexmo SMS service. This was the only documentation on their website.

During account set-up, you will be asked to supply Nexmo a CallBack URL for Delivery Receipt to which we will send a delivery receipt for each of your SMS submissions. This will confirm whether your message reached the recipient handset. The request parameters are sent via a GET (default) to your Callback URL and Nexmo will be expecting response 200 OK response, or it will keep retrying until the Delivery Receipt expires (up to 72 hours).

I have been looking for ways to do this, and so far I have this method from an example that I found on the Internet, although I'm not sure if this is correct. In any case, is this running on ASP.NET and on port 6563, as well as the port that I should listen to? I downloaded an application called ngrok, which should open my local web server on the Internet, so I ran the application and gave it a command to listen on port 6563, but no luck. I was messing with him, trying to find something to post this feature.

 [HttpPost] public ActionResult CallbackURL() { System.IO.StreamReader reader = new System.IO.StreamReader(HttpContext.Request.InputStream); string rawSendGridJSON = reader.ReadToEnd(); return new HttpStatusCodeResult(200); } 

Usually I can call the function directly to return the view, simply by visiting http://localhost:6563/Home/Index/CallbackURL So I inserted a breakpoint in the method signature, but it will only be called if I remove [HttpPost] from it. Any next steps I should try?

+6
source share
4 answers

So the problem I ran into was not related to my website, it was actually with IIS Express. It seems to block most of the traffic from foreign hosts, so you can make some settings before tunneling anything to your server. If you follow these guidelines, you must have a working server.

https://gist.github.com/nsbingham/9548754

https://www.twilio.com/blog/2014/03/configure-windows-for-local-webhook-testing-using-ngrok.html

0
source

First you need to remove the [HttpPost] bit because it clearly states that "parameters are sent via GET".

Then you should also remove the returned HttpStatusCodeResult (200), as it will return a 200 OK status code anyway if the error does not occur.

Then you should just read the values ​​from querystring or use model binding. Here is an example:

  public string CallbackURL() { string vals = ""; // get all the sent data foreach (String key in Request.QueryString.AllKeys) vals += key + ": " + Request.QueryString[key] + Environment.NewLine; // send all received data to email or use other logging mechanism // make sure you have the host correctly setup in web.config SmtpClient smptClient = new SmtpClient(); MailMessage mailMessage = new MailMessage(); mailMessage.To.Add(" ...@...com "); mailMessage.From = new MailAddress(" ..@....com "); mailMessage.Subject = "callback received"; mailMessage.Body = "Received data: " + Environment.NewLine + vals; mailMessage.IsBodyHtml = false; smptClient.Send(mailMessage); // TODO: process data (save to database?) // disaplay the data (for degugging purposes only - to be removed) return vals.Replace(Environment.NewLine, "<br />"); } 
+3
source

Until two weeks later, the Asp.Net team announced support for web hooks using Visual Studio.

Please see here for more details:

https://neelbhatt40.wordpress.com/2015/10/14/webhooks-in-asp-net-a-visual-studio-extension/

+2
source

Microsoft is working on ASP.NET WebHooks, a new addition to the ASP.NET family. It supports a lightweight HTTP template that provides a simple pub / helper model for working with web APIs and SaaS services.

See Microsoft ASP.NET Web Hosting View

+1
source

Source: https://habr.com/ru/post/976854/


All Articles