替代轮询的REST服务? [英] Alternative to polling on REST service?

查看:198
本文介绍了替代轮询的REST服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现一个REST WebService的,有不同的客户端(Silverlight中,WPF)。问题的关键是使用的HTTP优势。我必须推动更新TP我的客户(我不知道,究竟是什么,最好的选择)。大多数的教程是关于使用REST和彗星的茶亭应用程序,它不适合我的情况。我找不到任何样品,我塞纳里奥

I have to implement a REST WebService that has different Clients (Silverlight, WPF). The point is to make use of the http advantages. I must push updates tp my clients (and i have no idea, what is the best option for that). Most of the tutorials are about using REST and Comet for chating application, which is not suitable for my case. I cant find any samples for my senario

1)轮询一个好的做法呢?我将最终面临一些问题?哪一个?

1) Is polling a good practice? Will i eventually face some problems? Which one?

2)我要为大家介绍的Web客户端(Silverlight和也WPF)很快,但我不知道我们如何能够在AJAX轮询(从来没有使用AJAX),我想知道是否有可能做到这一点。

2) I want to introduce a web client (silverlight and also WPF) soon, but i dont know how we can poll in AJAX(never used AJAX) and i am wondering if it is possible to do it.

3)我想要的服务,是因为互操作性的休息。我想这与WPF,Silverlight的,JAVA,JAVASCRIPT(AJAX)和移动设备的工作。所以,如果我想介绍推送通知(如果它甚至可以使用REST),如何将它与WPF / Silverlight中,AJAX的工作。

3) I wanted the service to be REST because of interoperability. I want it to work with WPF, Silverlight, JAVA, Javascript(AJAX) and mobile devices. So if i want to introduce push notification(if it is even possible with REST), how will it work with WPF/Silverlight, AJAX.

如果你有code的例子,这将是AP preciated。

If you have code examples, it would be appreciated.

在此先感谢!

推荐答案

1)不好。但是,当使用HTTP无WebSockets的处理,你没有选择,要么投票或长轮询。如果是possbile使用的WebSockets和/或SingnalR,那么你就避免了投票,并提高性能。

1) Not good. But when dealing with HTTP without WebSockets you have no choice either polling or long polling. If it's possbile to use WebSockets and/or SingnalR, then you're avoiding of polling and improve performance.

2)jQuery.ajax

2) jQuery.ajax

http://api.jquery.com/jQuery.ajax/

3)看SignalR和SingnalR样品

3) Look at SignalR and SingnalR samples

http://signalr.net/

https://github.com/SignalR/SignalR

http://www.asp.net/signalr

和多了一个提示。从我的经验它几乎总是可以重新设计的客户端或者UI界面,以避免投票的。要确保有不同的投票站没有其他办法。而当你不工作与传统的应用程序,然后使用SignalR的WebSockets是用自己的方式

And one more hint. From my experience it's almost always possible to redesign clients or UI interface to avoid polling at all. Be sure that there is no other way except polling. And when you aren't working with legacy application then WebSockets using SignalR is your way

UPD : 如果说不是遗留应用和维护的话,肯定在微软堆栈答案REST服务将是有或没有SignalR REST服务的ASP.NET Web API。 SignalR是图书馆,这将有助于你和你的推送通知,即使客户端不支持WebSockets的。它的工作原理自适应,并且如果客户端不支持WebSockets的它会尝试使用其他技术,包括投票和长轮询。

UPD: When speaking not about legacy application or maintenance, then definitely for REST services in Microsoft stack answer will be ASP.NET Web API for REST service with or without SignalR. SignalR is library that will help you with your push notifications even if clients aren't supporting WebSockets. It works adaptively, and if client is not supporting WebSockets it will try to use other techniques including polling and long polling.

的NuGet包还inlcudes Silverlight的LIB

Nuget package inlcudes also silverlight lib

http://nuget.org/packages/Microsoft.AspNet.SignalR.Client /

看看SignalR控制台样本。这将是不是一个问题,从任何.NET客户端使用SignalR库 https://github.com/SignalR/Samples/tree/master/BasicChatConsole

Take a look at SignalR console sample. It will be not a problem to use SignalR libraries from any .NET client https://github.com/SignalR/Samples/tree/master/BasicChatConsole

有关如何使用的ASP.NET Web API的位置让REST服务示例和教程

Samples and tutorials on how to make REST services with ASP.NET Web API are here

http://www.asp.net/web-api

这篇关于替代轮询的REST服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆