Brad8118
Brad8118

Reputation: 4702

Can I Use Node.js to Call a C# Method?

I'm working on a Webforms project and I was looking at implementing node.js and issnode. We are using:

We have a page that takes a while to load and were looking at ways to improve its speed. There are a few counts that are being displayed on the page that are useful but are causing the page to load slowly. (We are displaying the total # of tasks, # of people in a group, and number of groups).

I was thinking that I'd be able to directly call my c# code from the node.js file. From the examples I've seen and what I've read it doesn't seem that is the solution I should be looking for. Since we are using EF and I'm not writing SQL queries it looks like I should be interacting with services.

So my question is, can I use Node.js to call my C# methods?

Upvotes: 4

Views: 10810

Answers (2)

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171411

Yes, you can now do this via Edge.js.

From http://www.infoq.com/articles/the_edge_of_net_and_node:

Why use Edge.js?

While many applications can be written exclusively in Node.js, there are situations that require or benefit from a combination of Node.js and .NET. You may want to use .NET and Node.js in your application for several reasons. .NET framework and NuGet packages provide a rich ecosystem of functionality that complements that of Node.js and NPM modules. You may have pre-existing .NET components you want to reuse in a Node.js application. You may want to use multi-threaded CLR to run CPU-bound computations that are not well suited for single-threaded Node.js. Or you may prefer to use .NET Framework and C# as opposed to writing native Node.js extensions in C/C++ to access mechanisms specific to the operating system not already exposed through Node.js.

Upvotes: 14

Chance
Chance

Reputation: 11285

Your question is a bit obscure so I'm going to pull out what I believe is the gist:

I was thinking that I'd be able to directly call my c# code from the node.js file.

I honestly don't know if this possible, I doubt it, but I'm not curious to figure it out because it's a bad idea.

From the examples I've seen and what I've read it doesn't seem that is the solution I should be looking for. Since we are using EF and I'm not writing SQL queries it looks like I should be interacting with services.

Absolutely, except EF nor SQL have absolutely nothing to do with why you shouldn't do this. I know that this can be a mental shift, especially in the .Net realm, but Node does exceptionally well at encouraging and empowering the use of micro applications that handle very specific tasks (think geocoding, analytics, timecode lookup, indexing, searching, notifications, etc etc) that can then be incorporated together via service calls or other mechanisms.

We have a page that takes a while to load and were looking at ways to improve its speed. There are a few counts that are being displayed on the page that are useful but are causing the page to load slowly. (We are displaying the total # of tasks, # of people in a group, and number of groups).

I haven't used .Net or EF in pretty long time but if I were to guess, I'd suggest you start by profiling this. I'd almost be willing to bet that you have an N+1 (or worse) problem that could easily be remedied.

Upvotes: 1

Related Questions