使用SilverLight构建插件式应用程序(九) —聊天插件客户端的实现
2008-10-30 11:48:57 来源:WEB开发网上边的代码由于都是使用的异步模式,看起来还是比较多的,但是道理还不是很复杂。这些都是模式相对固定的代码,下边就是我们针对聊天需要的代码了:
告诉系统,加入到聊天室:
public void Join(string userName)
{
ChatMessage chatMessage = new ChatMessage();
chatMessage.From = userName;
chatMessage.To = "";
chatMessage.Data = "";
//
Message message = Message.CreateMessage(channel.GetProperty<MessageVersion>(), "WindCloud/WSChatService/Join", chatMessage);
IAsyncResult resultChannel = channel.BeginSend(message, new AsyncCallback(OnSend), channel);
if (resultChannel.CompletedSynchronously)
{
CompleteOnSend(resultChannel);
}
}
最主要的一个方法,说话:
public void Say(ChatMessage chatMessage)
{
// The channel is now open. Send a message.
Message message = Message.CreateMessage(channel.GetProperty<MessageVersion>(), "WindCloud/WSChatService/Say", chatMessage);
try
{
IAsyncResult resultChannel = channel.BeginSend(message, new AsyncCallback(OnSend), channel);
if (resultChannel.CompletedSynchronously)
{
CompleteOnSend(resultChannel);
}
}
catch (Exception ex)
{
//channel = factory.CreateChannel(new EndpointAddress("http://localhost/ChatServer/Service.svc"));
IAsyncResult channelOpenResult = channel.BeginOpen(new AsyncCallback(OnOpenCompleteChannel), channel);
if (channelOpenResult.CompletedSynchronously)
{
CompleteOpenChannel(channelOpenResult);
}
IAsyncResult resultChannel = channel.BeginSend(message, new AsyncCallback(OnSend), channel);
if (resultChannel.CompletedSynchronously)
{
CompleteOnSend(resultChannel);
}
}
}
Tags:使用 SilverLight 构建
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接