简体   繁体   English

HTML5网络应用程序 - 选择服务器端技术

[英]HTML5 web app - Choosing serverside technology

Right now, I'm choosing technologies for a simple crossplatform mobile application. 现在,我正在为简单的跨平台移动应用程序选择技术。 Target systems are basically iOS, Windows Phone 7.5 and Windows 8. In the first step it's going to be a local wireless LAN application. 目标系统基本上是iOS,Windows Phone 7.5和Windows 8.第一步,它将成为本地无线局域网应用程序。

There are existing servers (using .net / WCF) that have all the data I want to display. 现有服务器(使用.net / WCF)具有我想要显示的所有数据。 The app will be polling every few seconds and give a live view on the data. 该应用程序将每隔几秒进行一次轮询,并对数据进行实时查看。 I won't be accessing the data server directly but have to create my own app-server in between. 我不会直接访问数据服务器,但必须在其间创建自己的app-server。

For the client I chose the HTML5, CSS, JavaScript (JQuery) approach to make it run in any modern browser. 对于客户端,我选择HTML5,CSS,JavaScript(JQuery)方法使其在任何现代浏览器中运行。 So I'll have to communicate via http. 所以我必须通过http进行交流。

My question is which technologie to use for the server side of my app. 我的问题是我的应用程序的服务器端使用哪种技术。 I have to receive http requests, get data (at best via WCF) from another server and send it to the client as xml or html. 我必须接收http请求,从另一台服务器获取数据(最好通过WCF)并将其作为xml或html发送到客户端。 (I am not quite sure whether server or client has to convert xml data into html) (我不太确定服务器或客户端是否必须将xml数据转换为html)

Searching the web I figured out two possible approaches: 在网上搜索我找出了两种可能的方法:

  • ASP.net ASP.net
  • Building my own simple http server using WCF 使用WCF构建我自己的简单http服务器

Looking at some ASP.net documentation and examples I got the impression that it just works the way I know from PHP etc... (Client sends request, server runs a script/programm, server sends response, programm terminates) I cannot keep objects in memory and run code independent of client requests. 看一些ASP.net文档和示例,我得到的印象是它只是按照我所知道的方式从PHP等... ...(客户端发送请求,服务器运行脚本/程序,服务器发送响应,程序终止)我无法保留对象在内存中运行独立于客户端请求的代码。 Or at least it's not designed to work like that. 或者至少它的设计不是那样的。 Is that correct? 那是对的吗?

That would force me to build my own very simple server that can answer a few specific http requests. 这将迫使我构建自己的非常简单的服务器,可以回答一些特定的http请求。

So my questions are: 所以我的问题是:

  • Are my assumptions about ASP.net correct? 我对ASP.net的假设是否正确? Or did I get something wrong? 或者我弄错了什么?
  • Would be an own http server the way to go? 将是一个自己的http服务器的方式去?
  • Can you recommend any other approaches (within the Microsoft / .net world)? 你能推荐任何其他方法(在Microsoft / .net世界中)吗?

Thanks in advance... 提前致谢...

You can have a look at the APE (Ajax push Engine) , as your application requires polling. 您可以查看APE(Ajax推送引擎) ,因为您的应用程序需要轮询。 Its built upon javascript and acts like an Comet server. 它建立在javascript之上,就像Comet服务器一样。

Alternatively you can also use one of the paid services for pushing(so that you shouldn't bother much about the server technologies) 或者,您也可以使用其中一种付费服务进行推送(这样您就不必担心服务器技术)

1) Pusher 1) Pusher

(From pusher homepage : Pusher is a hosted API for quickly, easily and securely adding scalable realtime functionality to web and mobile apps. ) (来自pusher主页: Pusher是一个托管API,可以快速,轻松,安全地为Web和移动应用程序添加可扩展的实时功能。

2) UrbanAirship 2) UrbanAirship

As @Fabio mentioned Python Tornado can be alternatively used for polling. 正如@Fabio提到的, Python Tornado可以替代地用于轮询。 Its a COMET server, and a lot of realtime web applications are built upon this. 它是一个COMET服务器,并且在此基础上构建了许多实时Web应用程序。 There are many tutorials available on polling with NodeJs . 有关NodeJ轮询的教程很多。 A simple google search lead me to this article. 一个简单的谷歌搜索引导我阅读这篇文章。

The data when accessed over mobile device is going to be costly. 通过移动设备访问时的数据将是昂贵的。 So, I would prefer to use JSON / XML to send the data over wire. 所以,我更愿意使用JSON / XML通过网络发送数据。 Would go with RESTful approach to retrieve the data with WCF Restful services / ASP.NET Web API in .NET stack. 将使用RESTful方法使用.NET堆栈中的WCF Restful services / ASP.NET Web API检索数据。 Also, if you would be considering the battery usage you should avoid polling and should use Signalling frameworks. 此外,如果您考虑使用电池,则应避免轮询,并应使用信令框架。 In .NET stack we have SignalR which does this. 在.NET堆栈中,我们有SignalR执行此操作。 This would notify the clients when the new data is available and client would initiate a new request to fetch the data. 这将在新数据可用时通知客户端,客户端将发起新请求以获取数据。

If you would like to experiment with new technologies, I would suggest using node.js at the server side and socket.io to communicate from the clients for signalling logic. 如果您想尝试新技术,我建议在服务器端使用node.js ,并使用socket.io从客户端进行信令逻辑通信。 Also, I would prefer to write the client application using phone gap & javascript so, that it could be easily ported to various platforms. 此外,我更喜欢使用手机间隙和JavaScript编写客户端应用程序,以便它可以轻松移植到各种平台。

There are countless web technologies that could do it but the thing that stands out for me is this: 有无数的网络技术可以做到,但对我来说突出的是这样的:

There are existing servers (using .net / WCF) that have all the data I want to display. 现有服务器(使用.net / WCF)具有我想要显示的所有数据。

So you've already got .net kicking around and I can't help thinking that the fastest way to get data out of a .net/WCF server is with a .net/WCF client. 所以你已经开始使用.net了,我不禁想到从.net / WCF服务器获取数据的最快方法是使用.net / WCF客户端。

For that reason alone I'd go with asp.net MVC. 仅仅因为这个原因,我会选择asp.net MVC。 Gives you a quick and easy path to getting to your data while leaving you with a lot of flexibility with how you handle the "V" part (straight HTML pages, ajax with xml data or json etc) 为您提供快速简便的数据获取途径,同时为您提供处理“V”部分(直接HTML页面,带有xml数据的jjax或json等)的灵活性。

Just last month asp.net mvc was released under the Apache 2.0 open source license. 就在上个月,asp.net mvc是在Apache 2.0开源许可下发布的。

For your use-case, I'd keep well away from asp.net webforms and asp.net ajax 对于你的用例,我会远离asp.net webforms和asp.net ajax

edit: 编辑:

I cannot keep objects in memory and run code independent of client requests. 我无法将对象保留在内存中并运行独立于客户端请求的代码。 Or at least it's not designed to work like that. 或者至少它的设计不是那样的。 Is that correct? 那是对的吗?

ASP.net (like a lot of application servers) has both session and application scopes you can store data in. You can also create background threads to perform work outside the standard request->response lifycycle. ASP.net(与许多应用程序服务器一样)具有可以存储数据的会话和应用程序范围。您还可以创建后台线程以执行标准请求 - >响应lifycycle之外的工作。

What I can say is: 我能说的是:

Use ALWAYS open source technologies :-). 使用ALWAYS开源技术:-)。 There are dozens of libraries/frameworks to write very good webservers but If you need high cuncurrency I can suggest to use event-based frameworks and not thread/process based ones. 有很多库/框架可以编写非常好的Web服务器但是如果你需要高功能,我可以建议使用基于事件的框架而不是基于线程/进程的框架。

Node.js (as said by @withadot) but also Python Tornado are a good choice. Node.js(由@withadot说)但是Python Tornado也是一个不错的选择。

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

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