首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何确保您不会得到WCF故障状态异常?

如何确保您不会得到WCF故障状态异常?
EN

Stack Overflow用户
提问于 2009-02-10 01:04:26
回答 5查看 108.7K关注 0票数 50

我得到了这个异常:

通信对象System.ServiceModel.Channels.ServiceChannel不能用于通信,因为它处于故障状态。

WCF服务使用默认的wsHttpBinding。无论我在哪里使用WCF,我都会以以下方式使用它:

代码语言:javascript
复制
using (var proxy = new CAGDashboardServiceClient())
{
    proxy.Open();
    var result = proxy.GetSiteForRegion(ddlRegions.SelectedValue);
    ddlSites.DataSource = result;
    ddlSites.DataBind();
    proxy.Close();
}

消息中显示的错误行似乎在上次proxy.close之后。不知道发生了什么。我正在从visual studio 08中启动该服务。

以下是跟踪信息:

代码语言:javascript
复制
The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

Server stack trace: 
  at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)

Exception rethrown at [0]: 
  at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
  at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
  at System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)
  at System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)
  at System.ServiceModel.ClientBase`1.Close()
  at System.ServiceModel.ClientBase`1.System.IDisposable.Dispose()
  at CAGDashboard.UserControls.ucVolunteerCRUDGrid.ddlRegions_SelectedIndexChanged(Object sender, EventArgs e) in C:\Documents and Settings\rballalx\My Documents\Visual Studio 2008\Projects\DashboardCAG\CAGDashboard\UserControls\ucVolunteerCRUDGrid.ascx.cs:line 81
  at System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e)
  at System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent()
  at System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
  at System.Web.UI.Page.RaiseChangedEvents()
  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2009-02-10 05:23:07

Stack Overflow用户

发布于 2011-02-19 12:36:36

更新

linked answer describes a cleaner, simpler way of doing the same thing with C# syntax.

原始帖子

这是Microsoft推荐的处理WCF客户端调用的方法:

有关详细信息,请参阅:Expected Exceptions

代码语言:javascript
复制
try
{
    ...
    double result = client.Add(value1, value2);
    ...
    client.Close();
}
catch (TimeoutException exception)
{
    Console.WriteLine("Got {0}", exception.GetType());
    client.Abort();
}
catch (CommunicationException exception)
{
    Console.WriteLine("Got {0}", exception.GetType());
    client.Abort();
}

附加信息

如此多的人似乎在WCF上问这个问题,以至于微软甚至创建了一个专门的示例来演示如何处理异常:

c:\WF_WCF_Samples\WCF\Basic\Client\ExpectedExceptions\CS\client

下载示例:C#VB

考虑到在这个问题上有这么多关于involving the using statement(heated?) Internal discussionsthreads的问题,我不会浪费我的时间去尝试成为一个代码牛仔并找到一种更干净的方法。我将接受它,并为我的服务器应用程序实现这种冗长的(但受信任的) WCF客户端。

票数 20
EN

Stack Overflow用户

发布于 2014-04-24 10:38:46

如果传输模式为Buffered,请确保MaxReceivedMessageSizeMaxBufferSize的值为。经过几个小时的努力,我刚刚通过这种方式解决了故障状态问题,并认为如果它对某人有帮助,我会在这里发布它。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/530731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档