我得到这个例外:

通信目的, 系统。ServiceModel.渠道。ServiceChannel, 不能用于通信 因为它是在故障的状态。

WCF服务使用的默认wsHttpBinding.我使用WCF在以下方式无论我在哪里使用:

using (var proxy = new CAGDashboardServiceClient())
{
    proxy.Open();
    var result = proxy.GetSiteForRegion(ddlRegions.SelectedValue);
    ddlSites.DataSource = result;
    ddlSites.DataBind();
    proxy.Close();
}

错误的线所示的信息似乎是之后的最后一代理。关闭。不知道是怎么回事。我推出的服务从内visual studio08.

这里是跟踪信息:

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)
有帮助吗?

其他提示


更新:

联答复描述了一种清洁的、更简单的方式做同样的事情C#语法。


原来的职位

这是Microsoft的建议的方式来处理WCF客户的电话:

更多详细信息见: 预期异常

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 Microsoft甚至创建一个专门的样品展示如何处理例外情况:

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

下载的样品:C#VB

考虑到有这么多问题 涉及使用声明, (热的?) 内部讨论螺纹 在这个问题上,我不会浪费我的时间试图成为一个码牛仔,并找到一个更清洁的方式。我只是吸它,并执行WCF客户这详细的(而可信的)的方式为我的服务器应用程序。

如果传输模式是的缓冲,然后确保的值的 MaxReceivedMessageSize 和<强> MAXBUFFERSIZE 是<强>相同即可。我只是解决了故障状态问题与它的格斗小时后这种方式,并认为,如果它可以帮助别人,我会张贴在这里。

此误差也可以通过具有零种方法标记有OperationContract特性引起的。这是建立一个新的服务,并测试它长的路时,我的问题。

类似瑞安Rodemoyer的答案,我发现,当在合同UriTemplate是无效的,你可以得到这个错误。就我而言,我是用两次相同的参数。例如:

/Root/{Name}/{Name}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top