使用 NFX 对 C# 类的静态成员函数的 erlang RPC 调用
本文关键字:函数 erlang RPC 调用 静态成员 使用 NFX | 更新日期: 2023-09-27 18:30:49
我正在尝试使用 nfx 从 erlang 调用 c# 静态成员函数。我遵循文档 http://blog.aumcode.com/2013/10/nfx-native-interoperability-of-net-with.html,我能够从 C# 调用 erlang:now 和从 erlang 调用 System.DateTime.UtcNow。但是当我尝试从 erlang 调用非系统时,出现错误
** 异常错误:右侧值不匹配 {错误, "未知类型:"程序"}
C# 代码:
namespace erlangIntegration {
public class Program {
static void Main(string[] args) {
var n = new ErlLocalNode("abc", new ErlAtom("'asdf'"));
n.AcceptConnections = false;
n.Start();
var m = n.CreateMbox("test");
var r = m.RPC("r@myPC", "erlang", "now", new ErlList());
Console.WriteLine("Remote time: {0}", r.ValueAsDateTime.ToString());
System.Console.WriteLine("My simple rpc: " + Program.FixedDate());
System.Console.WriteLine("Done. Press any key to exit.");
System.Console.ReadKey();
}
public static DateTime FixedDate() {
return new DateTime(2000, 12, 12);
}
}
}
Erlang 调用:
(r@myPC)2> f(Time), {ok, Time} = rpc:call('abc@myPC', 'System.DateTime', 'UtcNow', []), calendar:now_to_local_time(Time).
上面的调用工作返回 {{2016,1,18},{11,33,17}}然而
(r@myPC)12> f(Time), {ok, Time} = rpc:call('abc@myPC', 'Program', 'FixedDate', []), calendar:now_to_local_time(Time).
返回错误:** 异常错误:右侧值不匹配 {错误, "未知类型:"程序"}
我还尝试了erlangIntegration.Program并使用System命名空间。如何正确地对 c# 进行 rpc 调用?
Erlang 需要程序集限定名称作为 rpc:call 中的输入。因此,必须使用以下代码的"程序"输出代替"程序":
var obj = new Program();
//type from here has to be used in Erlang's call instead of 'Program'
System.Console.WriteLine("Type: " + obj.GetType().AssemblyQualifiedName);