ASP.NET 与 WCF 聊天
我正在寻找为 ASP.NET 页面实现聊天室界面。我正在学习 WCF,它似乎适合聊天应用程序。在我深入研究 WCF 之前,我想确定它是在 ASP.NET 中开发聊天应用程序的正确选择。有人可以提供任何反馈吗?
我发现了一些主要使用 Silverlight 和 WCF 进行聊天应用程序的示例应用程序。如果我选择不使用 Silverlight,是否有任何限制?
另外,任何我可以完全控制的 WCF 替代方案都会非常有帮助。我知道我可以使用 AJAX 轮询,关于优点/缺点的反馈都值得赞赏。谢谢。
I'm looking to implement a chatroom interface for an ASP.NET page. I'm in the process of learning WCF and it seems that it is appropriate for a chat application. Before I get too involved into WCF I want to be sure it is the right choice to make for developing a chat application in ASP.NET. Can anyone provide any feedback?
I found a few example applications that primarily use Silverlight with WCF for chat applications. Are there any limitations if I choose not to use Silverlight?
Also, any alternatives to WCF that I would have full control over would be very helpful. I'm aware I can use AJAX polling, feedback on advantages/disadvantaged are all appreciated. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用本机 ASP.Net 方法或 Silverlight 方法来开发美观的聊天应用程序。
唯一关心的是您的应用程序如何响应最终用户。这里的响应式是指系统如何让用户感受到其他用户的存在以及实时的聊天体验。有时这被称为真正实时。 (就像 gmail 和 facebook webchat 一样,用户可以看到用户的状态,说“用户正在打字或空闲”)
您可以使用这两种技术来实现这种级别的实时外观。但实施方式略有不同。
为了实现这一点,您必须在浏览器和服务器之间实现双工通信。因此,如果其他用户或其在场有任何响应,服务器将通知客户端。
以 ASP.Net 方式:
阿贾克斯。
以SilverLight方式:
希望这有帮助
You can use either Native ASP.Net approach or Silverlight approach to develop the good looking chat application.
The only concern is how your application is responsive to the end user. Here responsive means how the system let the user to feel the presense of other users and real time chat experience. This is refrenced sometime as really real time. (Like gmail & facebook webchat allows the user to see the user presense saying "user is typing or idle")
You can achive this level of realtime appearance using both these technologies. But implementation are little different.
In order to achive this, you must implement a duplex communication between the browser and server. So then server will notify the client if there is any response from other user or his presense.
In ASP.Net way:
AJAX.
In SilverLight way:
Hope this helps
Silverlight 客户端:
Silverlight 具有多种优势,包括 UI 灵活性、更强的 WCF 控制以及能够在客户端和服务器上使用相同的编程语言/工具。如果您选择 Silverlight,您可以更灵活地选择如何将数据传入和传出服务器,例如使用什么协议(TCP、HTML)以及如何传输数据。 Silverlight 的 UI 选项允许您通过完整的设计器支持和动画创建非常丰富且引人注目的体验。
ASP.NET 客户端:
创建简单的 HTML 客户端可能会更快,因为您不需要学习如何使用 Silverlight 来创建等效功能。即使只有 HTML、CSS 和 javascript,您仍然可以获得非常好的用户体验,仅以 gtalk 为例。使用 jQuery 等现代 JavaScript 库可以更轻松地快速创建复杂的应用程序,但仍易于理解和维护。
如果您想尝试一下、享受一些乐趣并学习新东西,也许可以考虑使用具有基本 WCF RESTful 接口的 ASP.NET 客户端。您仍然可以在客户端和服务器上灵活地控制发送哪些消息、客户端如何发出请求、在服务器上缓存等。有关 RESTful WCF 的易于理解的文章请查看 这篇文章由 Rick Strahl 撰写。
我编写了一个类似类型的应用程序来在 ASP.NET 应用程序中执行通知,并且在执行推送与从客户端轮询之间犹豫不决(请参阅 这个堆栈溢出问题)。我受到这个聊天示例的启发,该示例使用了一个非常简单的界面和客户端的推送通知。
Silverlight Client:
Silverlight has several advantages including UI flexibility, greater WCF control and being able the same programming language/tools on client and server. If you chose Silverlight you have more flexibility over how data is transferred to and from the server, such as what protocol to use (TCP, HTML) and how to transfer data. The UI options with Silverlight allow you create a very rich and compelling experience with the complete designer support and animations.
ASP.NET Client:
A simple HTML client may be faster to create since you would not need to learn how to use Silverlight to create the equivalent functionality. Even with just HTML, css and javascript, you can still have a very nice user experience just look at gtalk as an example. Using modern javascript libraries like jQuery make it even easier to create a complicated application quickly that is still easy to understand and maintain.
If you are looking to play around, have some fun and learn something new perhaps consider using a ASP.NET client with a basic WCF RESTful interface. You will still have alot of control and flexibily on both the client and server regarding what messages to send, how the client makes requests, caching on the server, etc. For an easy to digest post regarding RESTful WCF check out this post by Rick Strahl.
I wrote a similar type of application to perform notifications within an ASP.NET application and was waffleing between doing push vs. polling from the client (see this stack overflow question). I was inspired by this chat example which used a very simple interface and push notification for the client.
Silverlight 是 WCF 聊天应用程序的自然选择,因为您可以构建更丰富的用户界面,最重要的是您可以直接与 WCF 服务交互。如果您选择Ajax,那么所有客户端编程都需要在Javascript中完成。您可以创建一个支持 Ajax 的 WCF 服务,但实际上您需要通过代理与它交谈。这类似于 JSON Rest 之类的服务,并且不提供 WCF 技术的全部潜力(例如链接回调)。
WCF 的替代方案是实现简单的 HTTP 服务(例如使用 ASP.NET MVC)并使用 jQuery 等 javascript 库连接到它们。当然,轮询是必要的,但这就是大多数网站在这种情况下所做的事情。该解决方案的优点是跨平台,但可能需要更多的时间来开发,并且不能像Silverlight那样拥有丰富的接口。
Silverlight is the natural choice for a WCF chat application, since you can build a richer User Interface and most importantly you interact directly with the WCF services. If you choose Ajax, then all the client programming needs to be done in Javascript. You can create an Ajax enabled WCF service, but in reality you need to talk with it through a proxy. This is similar to a JSON Rest like service and doesn't offer the full potential of WCF technology (chaining callbacks for example).
An alternative to WCF is to implement simple HTTP services (using ASP.NET MVC for example) and connect to them with a javascript library like jQuery. Of course polling is necessary, but this is what most web sites in cases like this are doing anyway. The solution has the advantage of being cross-platform, but it will probably need more time to develop and can't have as rich interface as the Silverlight none.
我不了解 Silverlight,但对于常规 AJAX,我发现使用 ASP.NET MVC 控制器自己处理事情要容易得多。
I don't know about Silverlight, but for regular AJAX I've found handling things myself with an ASP.NET MVC controller to be much easier to work with.
查看下面的链接 - 这应该是一篇开始构建聊天应用程序的好文章
使用 WCF 和 WPF。非常简单易学的基本知识。
http://www.codeproject.com/KB/WCF/WCFWPFChat.aspx
您可以在上面的文章中找到附加的演示应用程序以及源代码。
编辑:
对于聊天应用程序,TCP 绑定是比 HTTP 绑定更好的选择。
请参考此 --> http://www.codeproject.com/KB/WCF/HttpBinding.aspx
Check out the below link - this should be a nice article to start building chat application
using WCF and WPF. Very Simple and easy to learn basic things.
http://www.codeproject.com/KB/WCF/WCFWPFChat.aspx
You can find the Attached Demo application along with Source code in the above article.
Edit:
For chat application TCP Binding is the best option than HTTP Binding.
kindly refer this --> http://www.codeproject.com/KB/WCF/HttpBinding.aspx