问题描述
当我尝试使用web服务我得到下面的异常。我的主要问题是,这是否会发生异常的时候?在服务器或客户端上?哪里是错误?服务器是否为各种故障抛出此?
我对我自己的,似乎有些变化工作
它实际上现在。我删除使用和服务客户端上添加索姆清理。
如果(服务= NULL&放大器;!&安培;!Service.State = CommunicationState.Faulted)
{
成功= TRUE;
Service.Close();
} }
赶上(异常前)
{
味精=错误+ Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace;
}
最后{
如果(!成功)
{
如果(服务!= NULL)Service.Abort();
}
}
这是个例外:
通信对象,System.ServiceModel.Channels.ServiceChannel,不能用于通信,因为它是处于故障状态。服务器堆栈跟踪:
在System.ServiceModel.Channels.CommunicationObject.Close(时间跨度超时)[0]时异常重新抛出:
在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天reqMsg,即时聊天retMsg)
在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培; MSGDATA,的Int32型)
在System.ServiceModel.ICommunicationObject.Close(时间跨度超时)
在System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Close(时间跨度超时)
在System.ServiceModel.ClientBase`1.Close()
在System.ServiceModel.ClientBase`1.System.IDisposable.Dispose()
在bNet.Services.Customers.Cres.Helios.ServiceForm.Send(ServiceFormAction任务)在C:\\ bNetProjects \\ BNET Web工具\\解决方案ROOT \\ bNet.Services \\客户\\ Cres的\\赫利俄斯\\ ServiceForm.cs:99行
在bNet.Web.Sites.Public.Customers.Cres.ServiceSkjema.Units.Page.ServiceFormControl.SubmitFormClick(Object发件人,EventArgs e)在C:\\ bNetProjects \\ BNET Web工具\\解决方案ROOT \\ bNet.Web.Sites.Public \\客户\\ Cres的\\ ServiceSkjema \\台\\页\\ ServiceFormControl.ascx.cs:192线
在System.Web.UI.WebControls.Button.OnClick(EventArgs的发送)
在System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串eventArgument)
在System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串eventArgument)
在System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,字符串eventArgument)
在System.Web.UI.Page.RaisePostBackEvent(NameValueCollection中POSTDATA)
在System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)
故障状态,意味着出现了的意外的服务器端异常。在早期的呼叫。
您应该已经得到了在客户端的异常过,也许你的code忽略它?
您可以通过重新打开连接解决它。但似乎你需要更好的错误处理。
When i try use a webservice i get the following exception. My main question is when does this exception happen? on the server or client? where is the error? Does the server throw this for a wide range of faults?
I did some changes on my own that seems to work
It actually works now. I removed using and added som cleanup on the service client.
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();
}
}
This was the exception:
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)
Faulted state means there has been an unexpected exception on the server side. In an earlier call.
You should have gotten an exception at the client side too, maybe your code ignores it?
You can solve it by reopening the connection. But it seems you need better error handling.
这篇关于WCF不能用于通信,因为它是处于故障状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!