Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I have this code in node.js and I need to convert it to C# code This method I have to implement it in my project to be consume from other platform.

But it is coded in Node.js and I am using ASP.NET MVC and I do not have idea in node.js anymore

app.post('/webhook', (req, res) => {

    var response

    console.log(req.headers)
    console.log(req.body)

    const message = `v0:${req.headers['x-zm-request-timestamp']}:${JSON.stringify(req.body)}`

    const signature = `lj5423j54235423`

    if (req.headers['x-zm-signature'] === signature) {

        if (req.body.event === 'endpoint.url_validation') {
            
            response = {
                message: {
                    plainToken: req.body.payload.plainToken,
                    encryptedToken: 'retwertwertewr5432fgds'
                },
                status: 200
            }

            console.log(response.message)

            res.status(response.status)
            res.json(response.message)
        } 
    } 
})


What I have tried:

My major problem here how to recieve req & res arguments in method and get data from header & body I try this but not works:

public ActionResult Hooksd(HttpRequest req, RestResponse res)
{
   ... 
}
Posted

1 solution

The standard answer for ANY "How do I convert thislanguage code to thatLanguage?" is always:
1) You must completely understand the code in the original language and any libraries being used.
2) You must completely understand the execution environment for the original language.
3) You must completely understand the target language and any available libraries you'll need.
4) You must completely understand the execution environment for the target language.
5) You must write completely new code in the target language that does what the original code does AND is written with points 1, 2, and 3 in mind. For example, Node easily allows for multiple client connections without you having to worry about the threading details. In C#, you have to think of those details and write your code to use either Tasks or Threads, and manage that stuff yourself.

Is there one way to write a Node server in C#? NOOOOOO! So there isn't a "one size fits all answer" to how you're going to convert the code.
 
Share this answer
 
Comments
Andre Oosthuizen 5-Dec-23 14:33pm    
My +5 because the question of "why is the earth flat" pops to mind. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900