Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Edge.js problem driving me crazy | I can call code through WebApi route but not from node server

Edge.js problem driving me crazy | I can call code through WebApi route but not from node server

Scheduled Pinned Locked Moved C#
databasehelpcsharpjavascripthtml
4 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alaric_
    wrote on last edited by
    #1

    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(&
    
    A 2 Replies Last reply
    0
    • A Alaric_

      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(&
      
      A Offline
      A Offline
      Alaric_
      wrote on last edited by
      #2

      ...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"

      A 1 Reply Last reply
      0
      • A Alaric_

        ...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"

        A Offline
        A Offline
        Alaric_
        wrote on last edited by
        #3

        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"

        1 Reply Last reply
        0
        • A Alaric_

          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(&
          
          A Offline
          A Offline
          Alaric_
          wrote on last edited by
          #4

          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"

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups