ASP.NET 与 WCF 聊天

发布于 2024-08-14 02:10:28 字数 269 浏览 3 评论 0原文

我正在寻找为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

意中人 2024-08-21 02:10:28

您可以使用本机 ASP.Net 方法或 Silverlight 方法来开发美观的聊天应用程序。

唯一关心的是您的应用程序如何响应最终用户。这里的响应式是指系统如何让用户感受到其他用户的存在以及实时的聊天体验。有时这被称为真正实时。 (就像 gmail 和 facebook webchat 一样,用户可以看到用户的状态,说“用户正在打字或空闲”)

您可以使用这两种技术来实现这种级别的实时外观。但实施方式略有不同。

为了实现这一点,您必须在浏览器和服务器之间实现双工通信。因此,如果其他用户或其在场有任何响应,服务器将通知客户端。

以 ASP.Net 方式:

  • 这完全由
    阿贾克斯。
  • 您必须使用 AJAX 模拟双工通信。 默认情况下 HTTP 不支持双工。它是单向的。它仅响应客户端请求。它不能直接调用客户端方法。
  • 现有技术可用于实现此目的。其中一种方法称为COMETReverseAJAX
  • 它只不过是长期存在的 AJAX 调用,如果服务器端发生预期事件,它将响应客户端,否则它保持平静。这篇 Comet(编程) 维基百科文章详细介绍了该方法。

以SilverLight方式:

  • 与普通的HTML页面相比,Silverlight提供了更好的用户体验。
  • 通过使用 SL,您可以利用 WCF Duplex 服务来实现服务器推送技术。根据 MSDN,它说

双工服务合约是一条消息
双方的交换模式
端点可以发送消息到
其他独立。复式服务,
因此,可以将消息发送回
客户端端点,提供
类似事件的行为

希望这有帮助

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:

  • This is been completely controlled by
    AJAX.
  • You have to simulate the Duplex communication using AJAX. By default HTTP doesnt support duplex. Its oneway. It only responses to client request. It cant directly invoke client method .
  • There are existing techniques available to achive this. One of the approach is called COMET or ReverseAJAX.
  • Its nothing but the long living AJAX calls, and will respond to the client if there is a expected event happening in server side, otherwise it stays calm. This Comet (programming) wikipedia article explains more about the approach.

In SilverLight way:

  • Silverlight gives much better User experience compared to normal HTML pages.
  • By using SL, you can make use of WCF Duplex services to implement the server push technique. As per MSDN, it says

A duplex service contract is a message
exchange pattern in which both
endpoints can send messages to the
other independently. A duplex service,
therefore, can send messages back to
the client endpoint, providing
event-like behavior

Hope this helps

┼── 2024-08-21 02:10:28

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.

请你别敷衍 2024-08-21 02:10:28

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.

可爱暴击 2024-08-21 02:10:28

我不了解 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.

陌上青苔 2024-08-21 02:10:28

查看下面的链接 - 这应该是一篇开始构建聊天应用程序的好文章
使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文