使用SilverLight构建插件式应用程序(九) —聊天插件客户端的实现
2008-10-30 11:48:57 来源:WEB开发网这个实体类的定义其实是可以自动生成的。
2:把对WCF服务的访问方法单独处理成一个对象,模式和结构基本和MSDN上那篇文章一样:
public void Start()
{
// Instantiate the binding and set the time-outs
PollingDuplexHttpBinding binding = new PollingDuplexHttpBinding()
{
ReceiveTimeout = TimeSpan.FromSeconds(45),
InactivityTimeout = TimeSpan.FromMinutes(1)
};
// Instantiate and open channel factory from binding
IChannelFactory<IDuplexSessionChannel> factory =
binding.BuildChannelFactory<IDuplexSessionChannel>(new BindingParameterCollection());
IAsyncResult factoryOpenResult =
factory.BeginOpen(new AsyncCallback(OnOpenCompleteFactory), factory);
if (factoryOpenResult.CompletedSynchronously)
{
CompleteOpenFactory(factoryOpenResult);
}
}
void OnOpenCompleteFactory(IAsyncResult result)
{
if (result.CompletedSynchronously)
return;
else
CompleteOpenFactory(result);
}
void CompleteOpenFactory(IAsyncResult result)
{
IChannelFactory<IDuplexSessionChannel> factory =
(IChannelFactory<IDuplexSessionChannel>)result.AsyncState;
factory.EndOpen(result);
// The factory is now open. Create and open a channel from the channel factory.
IDuplexSessionChannel channel =
factory.CreateChannel(new EndpointAddress(ServiceUrl));
IAsyncResult channelOpenResult =
channel.BeginOpen(new AsyncCallback(OnOpenCompleteChannel), channel);
if (channelOpenResult.CompletedSynchronously)
{
CompleteOpenChannel(channelOpenResult);
}
}
void OnOpenCompleteChannel(IAsyncResult result)
{
if (result.CompletedSynchronously)
return;
else
CompleteOpenChannel(result);
}
Tags:使用 SilverLight 构建
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接