question

BrianTkatch-9162 avatar image
0 Votes"
BrianTkatch-9162 asked ·

How to create a webhook listener in VB?

I want to use VB to create a webhook listener to consume messages from a service. The service does not have a listing in Nuget under Microsoft.AspNet.WebHooks.Receivers.*. The service requires an SSL certificate from an approved root authority. The system must listen on one of a few ports in their list. The service will be listen locally, not on Azure or any other service.

I have little idea of how to do this and so i have some very basic questions. Any additional guidance would be much appreciated.

1) Do i need to install IIS, or will the visual studio solution itself listen?

2) Must it be an AspNet project, or can i do this as a normal VB.Net project?

3) Is there a barebones example of a webhook listener? That is, what are the basics of listening in code?

dotnet-visual-basicdotnet-aspnet-general
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YijingSun-MSFT avatar image
1 Vote"
YijingSun-MSFT answered ·

Hi @BrianTkatch-9162,

1) Do i need to install IIS, or will the visual studio solution itself listen?
2) Must it be an AspNet project, or can i do this as a normal VB.Net project?

As far as I think,they are accroding to your requirment. If you use webhook only for yourself,you could create a normal project and the visual studio listen. And if you use it for Internet, I suggest you could create a mvc or webapi project and you need to install IIS.

3) Is there a barebones example of a webhook listener? That is, what are the basics of listening in code?

There is a example of a webhook listener using web service:

 [WebMethod]
 [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
 public void WebHookDataRecieve() //This method is called from Amazon Simple Notification Service when we receive a bounce.
 {
  string notification = "";
  using (var stream = new MemoryStream())
  {
    var request = HttpContext.Current.Request;
    request.InputStream.Seek(0, SeekOrigin.Begin);
    request.InputStream.CopyTo(stream);
    notification = Encoding.UTF8.GetString(stream.ToArray());//All of your data will be here in JSON format.
    //Simply parse it and access the data.
    }
 }

The basics are connecting with port and the data coming in JSON format from server.



If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Best regards,
Yijing Sun


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

BrianTkatch-9162 avatar image
0 Votes"
BrianTkatch-9162 answered ·

Thank you for replying. Please help me ascertain if i understood you correctly.

As far as I think,they are accroding to your requirment. If you use webhook only for yourself,you could create a normal project and the visual studio listen. And if you use it for Internet, I suggest you could create a mvc or webapi project and you need to install IIS.

We are using the Internet, as the broadcaster is a service over the Internet. So, i need to setup IIS. To that end, i installed IIS and changed the Bindings on "Default Web Site" from http on port 80 to https on port 3433. Is there anything else i need to do in IIS?

There is a example of a webhook listener using web service:

1) Create New Project->ASP.NET Web Application (.NET Framework)->Web API (Configure for HTTPS)
2) Project->Add References...->System.Web.Services
3) Project->Add Class...->Module
4) I converted the example code to VB:

 Imports System.IO
    
 Module Main
    
     <Services.WebMethod>
     Public Sub WebHookDataRecieve()
         Dim Notification As String = ""
    
         Using Stream = New MemoryStream()
             Dim Request = HttpContext.Current.Request
             Request.InputStream.Seek(0, SeekOrigin.Begin)
             Request.InputStream.CopyTo(Stream)
             Notification = Encoding.UTF8.GetString(Stream.ToArray()) 'All of your data will be here in JSON format.
             'Simply parse it and access the data.
         End Using
     End Sub
    
 End Module

I left out "ScriptMethod(ResponseFormat = ResponseFormat.Json)" as the documentation for ScriptMethodAttribute.ResponseFormat Property says of the ResponseFormat value:

One of the ResponseFormat values. The default is Json.

4) Project->(project-name) Properties->Web
- Don't open a page. Wait for a request from an external application.
- Project Url = https://localhost:3433/
- When prompted to create the virtual directory, clicked Yes


Is that correct?


· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @BrianTkatch-9162,

Yes,you are right.You add port to your website in IIS. Then publish the code to a virtual directory path that you will need to create within IIS. And you need to populate the secret key
values in the web.config.

1 Vote 1 ·