How to create a webhook listener in VB?

Boruch Tkatch 141 Reputation points
2020-11-18T21:34:22.777+00:00

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?

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,494 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,729 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,081 Reputation points
    2020-11-19T09:25:18.187+00:00

    Hi @Boruch Tkatch ,

    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

    1 person found this answer helpful.
    0 comments No comments

  2. Boruch Tkatch 141 Reputation points
    2020-11-19T21:31:29.253+00:00

    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?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.