ASP.NET Chat with WCF

孤街醉人 提交于 2019-11-29 23:23:54

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

smaclell

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 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.

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.

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!