您的位置:首页 > 其它

WCF服务访问超时的问题

2011-06-02 14:54 253 查看
今天写程序,突然发现使用WCF获取数据时,刷新20次就会报超时,捕获异常信息为WCF服务不可用。后来跟同事讨论了一下,发现clent端未在声明使用clent对象的之后没有做关闭处理,修正完毕后问题解决。

之所以是20次就超时是因为在Hosting的config中定义了访问限制:最大当前会话数为20……

<serviceThrottling maxConcurrentCalls="50" maxConcurrentInstances="30" maxConcurrentSessions="20" />


关闭处理需要在每个单独的try catch语句块之内调用close,不应该使用 using
语句(Visual Basic 中的 Using
),因为该语句可以屏蔽处于某些失败模式的异常。

具体参见:

WCF 客户端概述

MSDN提供了这样一段示例代码:

CalculatorClient wcfClient = new CalculatorClient();
try
{
Console.WriteLine(wcfClient.Add(4, 6));
wcfClient.Close();
}
catch (TimeoutException timeout)
{
// Handle the timeout exception.
wcfClient.Abort();
}
catch (CommunicationException commException)
{
// Handle the communication exception.
wcfClient.Abort();
}


其中分别使用了Close和Abort,查了一下,后者与前者的区别在于,后者为立即关闭。

具体参见:

ClientBase<
TChannel
>
成员

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐