简体   繁体   English

ASP.NET Web Api与Node.js

[英]ASP.NET Web Api vs Node.js

I have quite recently started to connect a web platform that I work on to other quite complex systems mostly written in C#. 我最近开始将我工作的网络平台连接到其他非常复杂的系统,这些系统大多用C#编写。 Most of my experience is in web development in PHP and JavaScript And I also have some experience in writing web services in WCF. 我的大部分经验都是使用PHP和JavaScript进行Web开发。我也有一些在WCF中编写Web服务的经验。

Sadly I had experienced many difficulties in writing WCF services for my PHP web platform, slow development, very (very) complicated configurations in-order to respond well in JSON and to work RESTful and more. 遗憾的是,我在为PHP Web平台编写WCF服务,开发速度慢,非常(非常)复杂的配置方面遇到了很多困难,以便在JSON中做出良好的响应并使用RESTful等等。

Naturally I started looking around at other technologies, one in particular caught my eye Node.js which might be perfect for me because I have quite a lot of experience in JavaScript and that way I won't need my windows server anymore. 当然,我开始环顾其他技术,特别是我的眼睛Node.js,这对我来说可能是完美的,因为我有很多JavaScript经验,这样我就不再需要我的Windows服务器了。 My other option is of course to keep writing services in C# but switch to ASP.NET Web API instead. 我的另一个选择当然是继续用C#编写服务,但转而使用ASP.NET Web API。 The switch will probably be much easier than from WCF to Node.js. 从WCF到Node.js,交换机可能要容易得多。

Any thoughts or suggestions in the matter? 对此事有何想法或建议? Does anyone have experience in writing web services in Node.js and can point me in the direction of a good tutorial? 有没有人有在Node.js中编写Web服务的经验,可以指向一个好的教程的方向? or am I way off and I shouldn't be using Node.js for web services at all? 或者我离开了,我不应该将Node.js用于网络服务?

I have just recently started working on express.js. 我刚刚开始研究express.js。 Let me tell you it's not for the fainthearted. 让我告诉你,这不适合胆小的人。 The whole mentality of "If you are already familiar with JS then that's half the battle." 整个心态“如果你已经熟悉JS,那那就是成功的一半。” really couldn't be further from the truth. 真的离真相太远了。 IE if you are a hardcore devops guy like me. IE如果你是像我这样的硬核人。

I have a unified build process for all my asp.net application build, test and coverage reporting, deployment, configuration management and code quality analysis all setup and automated. 我有一个统一的构建过程,用于我所有的asp.net应用程序构建,测试和覆盖报告,部署,配置管理和代码质量分析,所有设置和自动化。 It takes me literally 5 min to setup a Build process around a new project and have it tested, analysed, staged and shipped off to a production environment. 我花了5分钟来围绕一个新项目设置构建过程,并对其进行测试,分析,分阶段并运送到生产环境。 (And really so should all the devs in the world. But hey, who am I kidding.) Then there's the monitoring, logging, performance analysis and profiling. (世界上所有的开发者都应该这样。但是,嘿,我在开玩笑。)然后是监控,记录,性能分析和分析。 Again all well unified, orchestrated and centrally managed. 所有这些都很好地统一,协调和集中管理。

I'm not saying node.js/express.js doesn't have those, but you have to develope/learn a COMPLETELY NEW set of services and platform just to run node.js. 我不是说node.js / express.js没有那些,但你必须开发/学习一套完整的新服务和平台来运行node.js.

Hammering out a bunch of code is one thing. 敲定一堆代码是一回事。 Running a production system on a foreign technology is something else altogether. 在外国技术上运行生产系统完全是另一回事。

Unless you looking for trouble ahem i mean, challenge :D, stick to WebAPI. 除非你寻找的麻烦啊哈我的意思是,挑战:d,坚持的WebAPI。 WebDeploy is a god send. WebDeploy是神派。

BTW. BTW。 Use BasicHttpBinding with your WCF endpoint and get PHP to generate the client class from the WSDL. 将BasicHttpBinding与WCF端点一起使用,并使PHP从WSDL生成客户端类。 Yes. 是。 Soap is your answer, not an "easier to use rest". 肥皂是你的答案,而不是“更容易使用休息”。 Something like https://code.google.com/p/php-wsdl-creator/ . https://code.google.com/p/php-wsdl-creator/这样的东西。 Archiving the WSDL from the WCF endpoint also allows you to track with pin point accuracy of your service signature and format changes. 从WCF端点归档WSDL还允许您跟踪服务签名和格式更改的引脚点准确性。 It ensures type safety, and handles ser/de for you. 它确保了类型安全,并为您处理ser / de。 I don't care much about how ugly the message looks if I don't have to deal with it. 如果我不必处理它,我不太关心消息看起来多么丑陋。 And yes I have done it before with PHP and python. 是的,我之前用PHP和python做过。 Works flawlessly. 工作完美无瑕。

After 10 years of .net development, I wanted to use Nodejs for a mid sized application. 经过10年的.net开发,我想将Nodejs用于中型应用程序。 I am Just sharing my experience. 我只是分享我的经验。

Windows footprint Windows足迹

\n

Most of the new apps are deployed in cloud today. 大多数新应用程序今天都部署在云端。 For a Asp.net we need windows, though it works on Linux using mono, I am not confident enough about performance. 对于Asp.net,我们需要Windows,虽然它可以在Linux上使用单声道,但我对性能不够自信。 Windows server alone requires more than 750mb of ram, I wanted deploy my app on 1 GB memory server to reduce the cost. 单独的Windows服务器需要超过750mb的内存,我想在1 GB内存服务器上部署我的应用程序以降低成本。 So I wanted tiny OS. 所以我想要小OS。 Linux is proven for it. Linux已经证明了它。 In this case Linux wins, hence node js. 在这种情况下,Linux获胜,因此节点js。 However I believe Windows Nano Server can address this in near future. 但是我相信Windows Nano Server可以在不久的将来解决这个问题。 Now .Net (core) runs on linux 现在.Net(核心)在linux上运行

.Net Core .Net核心

Now .net core is the next Node JS. 现在.net核心是下一个Node JS。 It has open the door for C# to run on Linux and Mac. 它为C#在Linux和Mac上运行打开了大门。 Unity, Xmarin allows to create mobile apps and games too. Unity,Xmarin也允许创建移动应用和游戏。 We can now create .net standard library that can work on .net core, framework, xmarin and Unity. 我们现在可以创建.net标准库,可以在.net核心,框架,xmarin和Unity上工作。

Best time for C# developers. C#开发人员的最佳时间。

Quicker to code 更快速的代码

I can code well in C# as well as on js. 我可以在C#和js上编码。 So this is not a problem for me... 所以这对我来说不是问题......

Code clarity 代码清晰度

This is an important area. 这是一个重要的领域。 When the code base grows everything get complex in JavaScript. 当代码库增长时,JavaScript中的一切都变得复杂。 One person's javascript may not readable to another person. 一个人的javascript可能对另一个人不可读。 Many .net projects has large codebase but it is easily readable and Debuggable. 许多.net项目都有很大的代码库,但它易于阅读和调试。 A normal skilled team can manage C# codes in better manner. 普通技术团队可以更好地管理C#代码。 For node js the team has to be highly skilled in JS. 对于节点js,团队必须具备JS的高技能。 Average programmer may not read JavaScript properly. 普通程序员可能无法正确阅读JavaScript。

Simplicity 简单

nodeJS is very simple, No dlls, no GAC, No classes. nodeJS非常简单,没有dll,没有GAC,没有类。 It is tiny, really tiny code. 它是一个很小的,非常小的代码。 But "Code Clarity" is important for me than the number of lines I write. 但是“Code Clarity”对我来说比我写的行数重要。 For me simplicity means easy to read, not quicker to code. 对我来说简单意味着易于阅读,而不是更快速的代码。 I feel C# is simpler than JS when the code base grows. 当代码库增长时,我觉得C#比JS更简单。

Performance 性能

This is debatable. 这是值得商榷的。 I feel I can write good performance apps using both the technology. 我觉得我可以使用这两种技术编写性能良好的应用程序。

Open Source libraries 开源库

Nodejs wins here. Nodejs在这里获胜。 Too many packages, it is like tons of varieties in your breakfast. 太多的包裹,就像早餐中的吨品种一样。 It was hard for me to choose what I want. 我很难选择自己想要的东西。 I spent a week on ORM libraries for NodeJS, looked around Sequlizer, Sails, Knex, all of them is great. 我在NodeJS的ORM库上花了一个星期,环顾Sequlizer,Sails,Knex,所有这些都很棒。 But there are people completely re-coded their app from one framework to other. 但是有些人完全将他们的应用程序从一个框架重新编码到另一个框架。 That clearly shows that every framework is missing something. 这清楚地表明每个框架都缺少某些东西。 This never happened to me in .net world. 这在.net世界中从未发生过。 I am happy with Dapper, and Service stack ORM lite. 我很满意Dapper和服务堆栈ORM lite。

But we have more choice in node js, so if we choose properly everything is going to be fine. 但是我们在节点js中有更多的选择,所以如果我们选择得当,一切都会好起来的。

Docker 搬运工人

Docker is cool one. Docker很酷。 Who will say “I don't want it”? 谁会说“我不想要它”? This is the main thing I wanted for windows. 这是我想要的窗户的主要内容。 I heard Microsoft already doing something. 我听说微软已经做了些什么。 We have to wait and see… 我们要等等......

Platform portability 平台可移植性

Node js can run on almost on any OS, so what? 节点js几乎可以在任何操作系统上运行,那么呢? I am going to use one type of OS. 我将使用一种类型的操作系统。 AWS provides very few variations of linux. AWS提供的linux版本很少。 For me it doesn't matter what OS my app requires, my worry is how much cost it is. 对我来说,我的应用程序需要什么操作系统并不重要,我担心的是它的成本是多少。 In this case Windows and Linux are almost same priced by cloud providers. 在这种情况下,Windows和Linux的价格几乎与云提供商相同。 The only reason I like linux is It has very small footprint. 我喜欢linux的唯一原因是它的占地面积非常小。 Windows is not. Windows不是。 As I mentioned Windows Nano will address this. 正如我提到的,Windows Nano将解决这个问题。 So I am Ok to run my app on windows server. 所以我可以在Windows服务器上运行我的应用程序。

Now .Net core runs on linux so in docker. 现在.Net核心在linux上运行,所以在docker中运行。

Finally I decided to use C# and web api. 最后我决定使用C#和web api。 The main reason is my existing experience on it. 主要原因是我现有的经验。 However I will look back to node js for my next app. 但是我将回顾节点js以获取我的下一个应用程序。

No more look back. 不再回头看了。 Will continue with C# for server side, and react JS for client side. 将继续使用C#作为服务器端,并为客户端做出反应。

Both platforms have their pros & cons and, ultimately, both will do the job. 两个平台都有其优点和缺点,最终,两者都可以完成这项工作。

However, having used both, for me Node.js would win hands down for simplicity, development/deployment speed and performance which you get out of the box - and if it doesn't come out of the box, most likely there's a package for it . 然而,使用这两个,对我来说Node.js会因为简单,开发/部署速度和性能而赢得开箱即用 - 如果它没有开箱即用,很可能有一个包它

Node has been around for a few years now, however, it's only recently started to become more popular - so much so that Microsoft have vastly improved the tooling support in VS . Node已经存在了几年,然而,它最近才开始变得更受欢迎 - 以至于微软大大改进了VS中工具支持

What about the need for cross-platform portability? 对跨平台可移植性的需求如何? What if the need is for having web api/REST services that can be deployed on both Windows and Linux servers? 如果需要具有可在Windows和Linux服务器上部署的Web api / REST服务,该怎么办?

WCF - I don't think it can go to Linux (yet) (mongo??) WebAPI - Can't go to Linux (I think??) NodeJS - Cross platform runtime available. WCF - 我不认为它可以去Linux(尚未)(mongo ??)WebAPI - 无法进入Linux(我认为??)NodeJS - 跨平台运行时可用。 Code once deploy anywhere. 代码在任何地方部署。 xyz - What else do we have that can provide all these? xyz - 我们还有什么可以提供所有这些?

At least because of this, I would suggest the op for NodeJS 至少因为这个原因,我建议使用NodeJS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM