当我尝试使用web服务时,出现以下异常。我的主要问题是什么时候发生这种异常?在服务器或客户端?错误在哪里?服务器是否会针对各种各样的故障而抛出这个问题?WCF无法用于通信,因为它处于故障状态
我做我自己的一些变化,似乎工作
它实际上现在的作品。我删除了使用并在服务客户端添加了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)
异常调用堆栈实际上告诉你很多事情,你必须注意。例如,Dispose调用Close。因此,如果代理服务器已处于Faulted状态,则只能调用Abort,而不是Close或Dispose。幸运的是你找到了必要的改变。微软事实上有一篇很好的文章,强调推荐使用什么样的调用模式,http://msdn.microsoft.com/en-us/library/aa355056.aspx – 2012-02-23 08:40:34
请看这里以及http:// stackoverflow。 com/questions/2763592/the-communication-object-system-servicemodel-channels-servicechannel-can not be – 2014-02-26 15:26:08
也正是这个异常不是因为异常处理,而是为了试图返回没有'TableName'的'DataTable'。请参阅http://stackoverflow.com/questions/12702/returning-datatables-in-wcf-net – 2016-01-14 09:13:55