[英]Calling Node.js from C# .NET
Is it possible to call Node.js functions from a C# ASP.NET server?是否可以从 C# ASP.NET 服务器调用 Node.js 函数? I found the Edge.js library, but as I understood, it allows Node.js to call into C#.我找到了 Edge.js 库,但据我所知,它允许 Node.js 调用 C#。 I need the directly reverse solution.我需要直接反向解决方案。
Edge.js has not been updated since mid 2017 and Microsoft.AspNetCore.NodeServices has been obsoleted . Edge.js 自 2017 年年中以来未更新, Microsoft.AspNetCore.NodeServices 已过时。
My organization maintains a library, Jering.Javascript.NodeJS , that does everything Microsoft.AspNetCore.NodeServices did and more:我的组织维护一个库Jering.Javascript.NodeJS ,它可以完成 Microsoft.AspNetCore.NodeServices 所做的一切以及更多:
Jering.Javascript.NodeJS enables you to invoke javascript in NodeJS, from C#. Jering.Javascript.NodeJS 使您能够从 C# 调用 NodeJS 中的 javascript。 With this ability, you can use javascript libraries and scripts from your C# projects.借助此功能,您可以使用 C# 项目中的 javascript 库和脚本。
string javascriptModule = @"
module.exports = (callback, x, y) => { // Module must export a function that takes a callback as its first parameter
var result = x + y; // Your javascript logic
callback(null /* If an error occurred, provide an error object or message */, result); // Call the callback when you're done.
}";
// Invoke javascript in Node.js
int result = await StaticNodeJSService.InvokeFromStringAsync<int>(javascriptModule, args: new object[] { 3, 5 });
// result == 8
Assert.Equal(8, result);
Cross-platform support跨平台支持
Performance features 性能特点
Long-running application support长时间运行的应用程序支持
string
form, Stream
form, or from a file on disk.支持以string
形式、 Stream
形式或从磁盘上的文件调用 javascript。
Microsoft.AspNetCore.NodeServices
This provides a fast and robust way for .NET code to run JavaScript on the server inside a Node.js environment.这为 .NET 代码在 Node.js 环境中的服务器上运行 JavaScript 提供了一种快速而健壮的方式。 You can use this to consume arbitrary functionality from NPM packages at runtime in your ASP.NET Core app.您可以使用它在 ASP.NET Core 应用程序中在运行时使用来自 NPM 包的任意功能。
Most applications developers don't need to use this directly, but you can do so if you want to implement your own functionality that involves calling Node.js code from .NET at runtime.大多数应用程序开发人员不需要直接使用它,但如果您想实现自己的功能(涉及在运行时从 .NET 调用 Node.js 代码),则可以这样做。
Source: https://github.com/aspnet/JavaScriptServices来源: https : //github.com/aspnet/JavaScriptServices
只需使用“ express”在您的节点应用中公开一个http方法,然后使用“ RestSharp” /“ HttpClient”调用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.