I have library which contains some methods and property written in C# Language ,I want to access those methods from Node.js?
Below code is my C# Library code.
class Employee
{
public int Id { get; set; }
public string EmpName { get; set; }
public DateTime EmpDob { get; set; }
public Employee getEmpDetails()
{
Employee objEmployee = new Employee();
objEmployee.Id = 11203256;
objEmployee.EmpName = "John Miller";
objEmployee.EmpDob = System.DateTime.Now;
return objEmployee;
}
}So above code produced Employee.dll , Now I want use my getEmpDetails() from node js.
I have a C# class which contains plenty of methods. I have to access those methods from within Node.js, with the help of edge.js. The problem is all previous C# methods are synchronous, while calling from Node.js it says call as asynchronous.
So I wrote a wrapper class, and tried to call asynchronously, but I received this error:
ERROR: "Unable to access the CLR method to wrap through reflection. Make sure it is a public instance method"
public class Test
{
string XyzId;
string XyzRole;
public Test(string xyzId, string xyzRole)
{
XyzId = xyzId;
XyzRole = xyzRole;
}
private static Dictionary<int, Person> _people = new Dictionary<int, Person>();
// My asynchronous Method wrapper over synchronous Method
public async Task<object> ExecuteLogWarning(dynamic input)
{
Test tst = new Test("POC", "POC");
var task = Task.Run(() => LogWarningTest((string)input.errorCode, (string)input.message));
return task;
}
//synchronous method
public void LogWarningTest(string errorCode, string message)
{
_people.Add(Convert.ToInt32(errorCode), new Person(1, errorCode, message));
}
}
public class Person
{
public string FirstName;
public string LastName;
public int ID;
public Person(int id, string firstName, string lastName)
{
ID = id;
FirstName = firstName;
LastName = lastName;
}
}Node.js Code
var edge = require('edge');
var ExecuteLogWarning = edge.func({
assemblyFile:'Test.dll',
typeName:'Logging.Test',
methodName:'ExecuteLogWarning'
});
var joe = ExecuteLogWarning({
errorCode:"1",
message:"Message Runtime"
}, true);
var getPerson = edge.func({
assemblyFile:'Test.dll',
typeName:'Logging.Test',
methodName:'GetPerson'
});
console.log(getPerson(1, true));