WCF不能用于通信,因为它处于Faulted状态

当我尝试使用Web服务时,我得到以下exception。 我的主要问题是这个例外何时发生? 在服务器或客户端? 错误在哪里? 服务器是否针对各种故障抛出此信息?

我自己做了一些看似有效的改动

它现在实际上有效。 我删除了使用并在服务客户端上添加了som清理。

if (Service != null && Service.State != CommunicationState.Faulted) { success = true; Service.Close(); } } catch (Exception ex) { msg = "Error" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace; } finally{ if (!success) { if (Service != null) Service.Abort(); } } 

这是例外:

 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 bNet.Services.Customers.Cres.Helios.ServiceForm.Send(ServiceFormAction task) in C:\bNetProjects\bNet Web Tools\Solution root\bNet.Services\Customers\Cres\Helios\ServiceForm.cs:line 99 at bNet.Web.Sites.Public.Customers.Cres.ServiceSkjema.Units.Page.ServiceFormControl.SubmitFormClick(Object sender, EventArgs e) in C:\bNetProjects\bNet Web Tools\Solution root\bNet.Web.Sites.Public\Customers\Cres\ServiceSkjema\Units\Page\ServiceFormControl.ascx.cs:line 192 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 

故障状态意味着服务器端出现意外exception。 在之前的电话中。

你应该在客户端得到一个例外,也许你的代码忽略了它?

您可以通过重新打开连接来解决它。 但似乎你需要更好的error handling。

使用OperationContract属性标记零方法也可能导致此错误。 在构建新服务并对其进行长期测试时,这是我的问题。