Writing webhooks on localhost with Visual Studio and IIS Express

Writing webhooks on localhost with Visual Studio and IIS Express


Hi. In this video we’re going to look at
how you can use web hooks directly from your web application without the need to
publish your application to a live server or cloud service. Webhooks play
an important role in many web applications by handling user-defined
HTTP callbacks, web hooks can let your application know when a specific event
occurs on a third-party service. More and more services are offering web hooks by
allowing you to set a URL for HTTP requests. Software as a Service providers
such as Twilio, Dropbox SendGrid, PayPal and many others are now using web hooks. However before using these in your web application you usually need to either
publish to a live server or to Azure, so that your application can then be called
from the Internet. But what if you want to work with webhooks directly from
your local machine? Perhaps you want to debug your application without having to
publish it. Well today I’m going to show you how you can use the Visual Studio
extension called Conveyor which provides incoming access to your web project
through a tunnel enabling your webhooks to be called on localhost.
Conveyor is available on the Visual Studio extensions marketplace you can
download it directly from Visual Studio by going to the tools and then
extensions menu and in the online section search for Conveyor. Okay so to get started we’re going to
set up a simple webhooks MVC demo application in Visual Studio in
our case we’re going to set up the Twilio service to notify our application
when a text message or SMS has been received and respond with our own
specific message. This example project is designed to show you how Conveyor can be used to simplify the use of webhooks on your local machine if you need more
details about how to set up webhooks in the first place please take a look at
the numerous articles and projects online. Okay, let’s create a new project and
we’ll be creating an empty asp.net MVC project. We won’t be hosting in the cloud so you
don’t need to select Azure. In order to use the Twilio helper
libraries we will need to install the Twilio NuGet package via the package
manager console. Enter the following line into the console and hit return. Okay to
listen for the Twilio webhook we will create an MVC controller. Twilio will
call our webhook once an SMS text message has been received so right click
on the Controllers folder in your project and select add and then
Controller and add an empty MVC 5 Controller. You can name your controller
anything you like it doesn’t matter. Next you will need to add the Using
statements to import the Twilio namespaces and change the Controller
class to inherit from the Twilio Controller. Bext add the following code to the
project. Of course you can set up web hooks however you wish but for our
example we have our response message set as ‘Hello World’ so when our web hook
receives a notification of an SMS text message to our Twilio number it will
respond with our own message. So now we can go ahead and run our application. Now as
this is a simple project with the only content being our Controller, you will
see an error message, that doesn’t matter, we just need our project to be running
in Visual Studio so we can make use of the webhook. Now the application is
running we can use Conveyor to obtain a publicly accessible URL that we can
provide to Twilio. If you go ahead and click access over internet button and
Conveyor it will provide us with the URL that we need you may need to register
for a conveyor account if you haven’t already done so. Calls to the conveyor
cloud URL are tunnelled to your localhost so we can add the Controller name
to the Conveyor cloud URL and then add that to the Twilio settings. That’s it. We’re ready to test it out now.
I’ll add a breakpoint so we can see what’s happening a bit clearer. Now when I send an SMS text to my Twilio
number our breakpoint is hit. Clicking continue you can see the
message from our application is sent back to the mobile number. If we pause the application we can alter
the message. I’ll send another text to my Twilio
number without the breakpoint this time. You can see the new message is sent back
to us. Oh as we’re using a free Twilio account each of the messages from Twilio
has the trial account prefix to it so you can ignore that. And that’s it. As
conveyor tunnels through your firewall and handles all the configuration
settings it makes it extremely easy to set up direct access to your web
application. In the same way conveyor can actually be used to test your
application from a variety of devices either attached to your local network or
over the Internet. Well I hope you found this video useful,
if you have any questions or comments please do let us know, thank you.

2 comments

  1. Great video, thanks man!

    Unfortunately Conveyor has stopped free sign ups for their service. I was hoping to test my SendGrid webhook processor but I'd have to pay $5 a month for Conveyor.

    Does anyone know how I could test a webhook without publishing a public facing website? Sure is annoying to test.

Leave a Reply

Your email address will not be published. Required fields are marked *