c# – WCF由于处于故障状态,无法用于通信

前端之家收集整理的这篇文章主要介绍了c# – WCF由于处于故障状态,无法用于通信前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我尝试使用webservice我得到以下异常.我的主要问题是这个异常何时发生?在服务器或客户端?错误在哪里?服务器是否为广泛的故障引发这种错误

我自己做了一些改变,似乎工作

它实际上现在工作.我删除了使用并在服务客户端添加了一些清理.

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)
@H_403_12@

解决方法

故障状态表示服务器端出现意外异常.在以前的通话中.

你也应该在客户端遇到异常,也许你的代码忽略它?

您可以通过重新打开连接来解决它.但似乎你需要更好的错误处理.

@H_403_12@ @H_403_12@

猜你在找的C#相关文章