Silverlight 3 Chat application with WCF Duplex Binding

本文介绍了一款基于Silverlight的聊天应用程序的工作原理和技术细节。该应用通过ChatHost服务器接受来自客户端的连接请求,并将消息广播给所有在线用户。为了解决跨域问题,服务器提供了ClientAccessPolicy文件以允许Silverlight访问不同域名的服务。文章还提供了部署指南和源代码下载链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How does the application work?
The ChatHost accepts connections from all Silverlight clients. Silverlight calls a login method on the ChatHost and the ChatHost holds a list of all connected clients.

When a Silverlight clients sends a message to the chatbox, the ChatHost will broadcast this message to all connected clients.

If it fails to deliver the message to the client, the client probably closed it's browser and is removed from the connected clients list.

 

Live example:

 

Tip: If there are no people to chat with, invite a friend or open 2 browser windows.

Client Access Policy
The ChatHost server is running on a different port number than the Silverlight webpage's (port 80). Because port 80 is used by IIS, the ChatHost can't host the WCF services on the same port number.
But Silverlight is not automatically allowed to access services on other servers/ports. So a Client Access Policy file (clientaccesspolicy.xml) must be provided by the target server.
The ChatHost can provide this file to Silverlight through the CrossDomainService.cs which is included in the ChatHost project.


How to get this working on your server?

  1. Download the source code
  2. Modify the App.config of the ChatHost and change the ServiceBase setting. Change the server name and port number to the name of your server and a port number you like.
  3. Modify the Silverlight project and specify the server name and port of the WCF endpoint (which you modified at step 2).
  4. Compile the projects
  5. Run the server
  6. Run Silverlight project

Download the full source code of the project here.

 

Silverlight Sockets
Are you looking for a socket based Silverlight chat application?
http://www.michielpost.nl/PostDetail_7.aspx

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值