Edge.js problem driving me crazy | I can call code through WebApi route but not from node server
-
So I've run into a snag that is driving me insane. I've built two async connectors: one is to a SQL Server database and have exposed it through WebApi (for a .NET sanity check) and through a Task interface exposed for node consumers. The second uses a TaskCompletionSource that wraps an arbitrary list with a Task (for a node sanity check). When I Debug the Web Api project and nav to my route that is attached to the database, everything does fine. The data from my database is returned to the browser. When I node my server attached to the mocked async route, everything does fine. My mock is returned to my server and I spool the object to the console. HOWEVER...when I try to wire node in to consume the attached data connector, when I browse to the open node port, my server crashes with an error "Process is terminated due to StackOverflowException." The frustration comes from the fact that I'm doing nothing fancy and the connector retrieves data just fine from an api route. My server:
var edge = require('edge');
var http = require('http');
var port = process.env.PORT || 8088;var userRepository = {
getUsers: edge.func({
assemblyFile:'Edge.Test.dll',
typeName: 'Edge.Test.DataConnector',
methodName: 'Invoke'
})
};function logError(error, response){
console.log('[Error]:{' + error+'}');
response.writeHead(200, { 'Content-Type': 'text/plain'});
response.write('[Error]:' + error);
response.end("");
}http.createServer(function(request,response){
console.log('Creating Server...');
response.writeHead(200, {'Content-Type':'text/html'});
var payload = {};
console.log('[Before][userRepository.getUsers]');
userRepository.getUsers(payload, function(error, result){
console.log('[Result][userRepository.getUsers]');
if(error){logError(error, result);return;}
if(result){
response.write("<ul>");
result.forEach(function(user){
console.log("[Response contains User]{"+user.FirstName+"|"+user.LastName+"}");
response.write("<li>" + user.FirstName + " " + user.LastName);
});response.end("</ul>"); } else{ response.end(&
-
So I've run into a snag that is driving me insane. I've built two async connectors: one is to a SQL Server database and have exposed it through WebApi (for a .NET sanity check) and through a Task interface exposed for node consumers. The second uses a TaskCompletionSource that wraps an arbitrary list with a Task (for a node sanity check). When I Debug the Web Api project and nav to my route that is attached to the database, everything does fine. The data from my database is returned to the browser. When I node my server attached to the mocked async route, everything does fine. My mock is returned to my server and I spool the object to the console. HOWEVER...when I try to wire node in to consume the attached data connector, when I browse to the open node port, my server crashes with an error "Process is terminated due to StackOverflowException." The frustration comes from the fact that I'm doing nothing fancy and the connector retrieves data just fine from an api route. My server:
var edge = require('edge');
var http = require('http');
var port = process.env.PORT || 8088;var userRepository = {
getUsers: edge.func({
assemblyFile:'Edge.Test.dll',
typeName: 'Edge.Test.DataConnector',
methodName: 'Invoke'
})
};function logError(error, response){
console.log('[Error]:{' + error+'}');
response.writeHead(200, { 'Content-Type': 'text/plain'});
response.write('[Error]:' + error);
response.end("");
}http.createServer(function(request,response){
console.log('Creating Server...');
response.writeHead(200, {'Content-Type':'text/html'});
var payload = {};
console.log('[Before][userRepository.getUsers]');
userRepository.getUsers(payload, function(error, result){
console.log('[Result][userRepository.getUsers]');
if(error){logError(error, result);return;}
if(result){
response.write("<ul>");
result.forEach(function(user){
console.log("[Response contains User]{"+user.FirstName+"|"+user.LastName+"}");
response.write("<li>" + user.FirstName + " " + user.LastName);
});response.end("</ul>"); } else{ response.end(&
...any ideas? I was able to get the data from SQL Server marshaled back to node by using Express, but it would only execute successfully on server start up (I called the repository method directly on server start and then spooled the results to the console) But if I try to activate the '/users' route, I get the StackOverflow exception...but it is only occurring if the CLRMethod I'm using is attached to the database. If I manually build the Task to return and stuff a list of hard coded objects in it, I have a happy path.
"I need build Skynet. Plz send code"
-
...any ideas? I was able to get the data from SQL Server marshaled back to node by using Express, but it would only execute successfully on server start up (I called the repository method directly on server start and then spooled the results to the console) But if I try to activate the '/users' route, I get the StackOverflow exception...but it is only occurring if the CLRMethod I'm using is attached to the database. If I manually build the Task to return and stuff a list of hard coded objects in it, I have a happy path.
"I need build Skynet. Plz send code"
Solved. I thought there was something funny about my express route...there was no serialization of the response.
app.get('/users', function(request, response){
users.repository.getUsers({}, function(error, result){
response.json(result);
});
});Works beautifully now.
"I need build Skynet. Plz send code"
-
So I've run into a snag that is driving me insane. I've built two async connectors: one is to a SQL Server database and have exposed it through WebApi (for a .NET sanity check) and through a Task interface exposed for node consumers. The second uses a TaskCompletionSource that wraps an arbitrary list with a Task (for a node sanity check). When I Debug the Web Api project and nav to my route that is attached to the database, everything does fine. The data from my database is returned to the browser. When I node my server attached to the mocked async route, everything does fine. My mock is returned to my server and I spool the object to the console. HOWEVER...when I try to wire node in to consume the attached data connector, when I browse to the open node port, my server crashes with an error "Process is terminated due to StackOverflowException." The frustration comes from the fact that I'm doing nothing fancy and the connector retrieves data just fine from an api route. My server:
var edge = require('edge');
var http = require('http');
var port = process.env.PORT || 8088;var userRepository = {
getUsers: edge.func({
assemblyFile:'Edge.Test.dll',
typeName: 'Edge.Test.DataConnector',
methodName: 'Invoke'
})
};function logError(error, response){
console.log('[Error]:{' + error+'}');
response.writeHead(200, { 'Content-Type': 'text/plain'});
response.write('[Error]:' + error);
response.end("");
}http.createServer(function(request,response){
console.log('Creating Server...');
response.writeHead(200, {'Content-Type':'text/html'});
var payload = {};
console.log('[Before][userRepository.getUsers]');
userRepository.getUsers(payload, function(error, result){
console.log('[Result][userRepository.getUsers]');
if(error){logError(error, result);return;}
if(result){
response.write("<ul>");
result.forEach(function(user){
console.log("[Response contains User]{"+user.FirstName+"|"+user.LastName+"}");
response.write("<li>" + user.FirstName + " " + user.LastName);
});response.end("</ul>"); } else{ response.end(&
For completeness' sake, I thought I'd provide some additional clarification. Notice in the original code that I posted that in the GetUsers() method that calls the data connector, I did not await the Resolution of the promise. In fact, I didn't need to resolve that manually, so I changed the code that read like this...
var connector = new Data.SqlServer();
Task.Factory.StartNew(() => { source.SetResult(connector.GetUsersSync()); }); return await task;
to instead read like:
DataConnector connector = new DataConnector();
return connector.GetUsers();and then, to keep the async task from "completing before another async task could complete", I had to await the call to the data connector
DataConnector connector = new DataConnector();
return await connector.GetUsers();It was really easy once I was able to spot it. I just skipped over the StartNew(() call every time I was analyzing; took way too many looks to notice that it was not executing asynchronously.
"I need build Skynet. Plz send code"