赞
踩
http://social.microsoft.com/Forums/zh-CN/wcfzhchs/thread/4ed44acc-859c-4c9b-bdfa-34142497e1d7
您好,我写的WCF程序在运行一段时间后,时常报出以下错误:
通信对象 System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为其处于“出错”状态。
当我把IIS网站关闭重启后,错误就消除了。
请问这是怎么回事啊?
Hi,LiPei
这个错误好像以前有人遇到过。
如果客户端代理建立以后,长时间不使用,就会出现出错状态,进而无法使用。
你在客户端调用代理的时候做一个判断,如果通道出错,进行重新连接,。或者重新new一个客户端代理。以前的销毁掉。
试验一下
Frank.Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
老徐的博客: http://frank_xl.cnblogs.com
xu lei,
你好,
我的程序最近又开始报这个错误。这个错误在我使用IE直接浏览时才会出现,当我用VS调试运行时就不会出现这个问题。
我的使用代理的代码是这样写的,请你帮我看看吧。
public static List<ArticleCatalogInfo> GetArticleCatalogInfos()
{
using (ArticleCatalogServiceProxy ACSProxy = new ArticleCatalogServiceProxy())
{
if (!enableCaching)
{
if (ACSProxy.State != CommunicationState.Opened)
{
ACSProxy.Open();
}
return ACSProxy.GetArticleCatalogInfos().ToList<ArticleCatalogInfo>();
}string cacheKey = "ArticleCatalog_GetArticleCatalogInfos";
List<ArticleCatalogInfo> ACInfoList = (List<ArticleCatalogInfo>)HttpRuntime.Cache[cacheKey];
if (ACInfoList == null)
{
if (ACSProxy.State != CommunicationState.Opened)
{
ACSProxy.Open();
}ACInfoList = ACSProxy.GetArticleCatalogInfos().ToList<ArticleCatalogInfo>();
AggregateCacheDependency acd = DependencyFacade.GetArticleCatalogDependency();
AddToCache(cacheKey, ACInfoList, acd);
}
return ACInfoList;
}
}
做最好的自己
Hi,
不要使用静态static的方法,这样连接会再加载类库的时候就实例化了,长时间肯定通道出错.~
Hi,LiPei
这个错误好像以前有人遇到过。
如果客户端代理建立以后,长时间不使用,就会出现出错状态,进而无法使用。
你在客户端调用代理的时候做一个判断,如果通道出错,进行重新连接,。或者重新new一个客户端代理。以前的销毁掉。
试验一下
Frank.Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
老徐的博客: http://frank_xl.cnblogs.com
你好,Xu Lei,
你说对了,就是因为闲置时间过长需要new一下。你在这方面得造诣不浅啊。总是能帮我们解决问题。
祝你早日成为WCF的Professional,呵呵,应该说现在你已经可以称为Professional了。
做最好的自己
xu lei,
你好,
我的程序最近又开始报这个错误。这个错误在我使用IE直接浏览时才会出现,当我用VS调试运行时就不会出现这个问题。
我的使用代理的代码是这样写的,请你帮我看看吧。
public static List<ArticleCatalogInfo> GetArticleCatalogInfos()
{
using (ArticleCatalogServiceProxy ACSProxy = new ArticleCatalogServiceProxy())
{
if (!enableCaching)
{
if (ACSProxy.State != CommunicationState.Opened)
{
ACSProxy.Open();
}
return ACSProxy.GetArticleCatalogInfos().ToList<ArticleCatalogInfo>();
}
string cacheKey = "ArticleCatalog_GetArticleCatalogInfos";
List<ArticleCatalogInfo> ACInfoList = (List<ArticleCatalogInfo>)HttpRuntime.Cache[cacheKey];
if (ACInfoList == null)
{
if (ACSProxy.State != CommunicationState.Opened)
{
ACSProxy.Open();
}
ACInfoList = ACSProxy.GetArticleCatalogInfos().ToList<ArticleCatalogInfo>();
AggregateCacheDependency acd = DependencyFacade.GetArticleCatalogDependency();
AddToCache(cacheKey, ACInfoList, acd);
}
return ACInfoList;
}
}
xu lei,
你好,
我的程序最近又开始报这个错误。这个错误在我使用IE直接浏览时才会出现,当我用VS调试运行时就不会出现这个问题。
我的使用代理的代码是这样写的,请你帮我看看吧。
public static List<ArticleCatalogInfo> GetArticleCatalogInfos()
{
using (ArticleCatalogServiceProxy ACSProxy = new ArticleCatalogServiceProxy())
{
if (!enableCaching)
{
if (ACSProxy.State != CommunicationState.Opened)
{
ACSProxy.Open();
}
return ACSProxy.GetArticleCatalogInfos().ToList<ArticleCatalogInfo>();
}string cacheKey = "ArticleCatalog_GetArticleCatalogInfos";
List<ArticleCatalogInfo> ACInfoList = (List<ArticleCatalogInfo>)HttpRuntime.Cache[cacheKey];
if (ACInfoList == null)
{
if (ACSProxy.State != CommunicationState.Opened)
{
ACSProxy.Open();
}ACInfoList = ACSProxy.GetArticleCatalogInfos().ToList<ArticleCatalogInfo>();
AggregateCacheDependency acd = DependencyFacade.GetArticleCatalogDependency();
AddToCache(cacheKey, ACInfoList, acd);
}
return ACInfoList;
}
}
做最好的自己
Hi,
不要使用静态static的方法,这样连接会再加载类库的时候就实例化了,长时间肯定通道出错.~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。