示例 - 如何在NodeJS中调用SS生成的DLL
2024-10-02 08:04:15
要想在NodeJS中调用SS生成的DLL, 需要借助EdgeJS.
EdgeJS: http://tjanczuk.github.io/edge/
如果你还不知道如何在SS中生成DLL, 请查看: Spider Studio 新版本 (x-mas) - 可以引入第三方程序集, 可以将脚本生成为DLL
下面以曾经写过的XML/JSON互转的脚本为例 (C#中另辟蹊径解决JSON / XML互转的问题) 说明如何在NodeJS中应用SS DLL:
1. 安装edgejs
npm install edge
2. 为www.utilities_online.info.XmlJsonConverter.dll编写一个javascript的代理脚本
一共两个方法, Xml2Json & Json2Xml:
var edge = require('edge'); exports.xml2json = edge.func({
source: function() {/* using System.Threading;
using System.Threading.Tasks;
using www.utilities_online.info; public class Startup
{
public async Task<object> Invoke(object input)
{
object result = null;
Thread t = new Thread(new ParameterizedThreadStart((p) => {
using(var proxy = new XmlJsonConverter())
{
proxy.Init();
result = proxy.Xml2Json(p.ToString());
}
} ));
t.SetApartmentState(ApartmentState.STA);
t.IsBackground = true;
t.Start(input);
while (t.ThreadState != ThreadState.Stopped)
{
Thread.Sleep(100);
}
return result;
}
}
*/},
references: [ __dirname + '\\www.utilities_online.info.XmlJsonConverter.dll' ]
}); exports.json2xml = edge.func({
source: function() {/* using System.Threading;
using System.Threading.Tasks;
using www.utilities_online.info; public class Startup
{
public async Task<object> Invoke(object input)
{
object result = null;
Thread t = new Thread(new ParameterizedThreadStart((p) => {
using(var proxy = new XmlJsonConverter())
{
proxy.Init();
result = proxy.Json2Xml(p.ToString());
}
} ));
t.SetApartmentState(ApartmentState.STA);
t.IsBackground = true;
t.Start(input);
while (t.ThreadState != ThreadState.Stopped)
{
Thread.Sleep(100);
}
return result;
}
}
*/},
references: [ __dirname + '\\www.utilities_online.info.XmlJsonConverter.dll' ]
});
3. 编写服务脚本 www.utilities_online.info.XmlJsonConverter.js
var http = require('http');
var xmlJson = require('./www.utilities_online.info.XmlJsonConverter.proxy.js'); var person = { person:{ name:'Mike', age: }}; var proxy = http.createServer(function (req, res) {
res.writeHead(, {'Content-Type': 'application/xml'});
var xml = xmlJson.json2xml(JSON.stringify(person), true);
console.log(xml);
res.end(xml);
}).listen();
4. 运行, 查看效果:
最新文章
- 【Win 10 应用开发】Sqlite 数据库的简单用法
- C Primer Plus_第8章_字符输入输出和输入确认_编程练习
- Linux 下从头再走 GTK+-3.0 (五)
- Elasticsearch-2.3.x填坑之路
- 解决My eclipse 工程发布时端口占用问题
- thrift
- ZOJ 1099 HTML
- OS X Git连接github
- [!] CocoaPods was not able to update the `master` repo...
- Delphi TdxBarManager通过代码生成菜单
- delphi 集合的用法
- SLAM入门之视觉里程计(5):单应矩阵
- [Swift]LeetCode413. 等差数列划分 | Arithmetic Slices
- IDEA打包jar包
- es安装elasticsearch-sql插件
- DefWindowProc是一个会产生消息的函数
- mysql 多列索引的生效规则,生成1000w数据的存储过程
- 34.js----JS 开发者必须知道的十个 ES6 新特性
- [bug]不包含“AsNoTracking”的定义
- 截图保存 matlab
热门文章
- NGUI系列教程七(序列帧动画)
- Install certificates needed for Visual Studio offline installation
- div+css 和 xhtml+css是一回事么?
- 分享六个基于Bootstrap的实用开发教程和模板演示
- mysql查找数据库中是否已经存在某张表
- http协议中content-length 以及chunked编码分析
- [Oracle] SQL*Loader 详细使用教程(5)- 典型例子
- IIS7 大文件上传 asp.net iis配置
- Effective java读书札记第一条之 考虑用静态工厂方法取代构造器
- 隐函数画图with R