简体   繁体   English

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

[英]WCF Cannot be used for communication because it is in the Faulted state

When i try use a webservice i get the following exception. 当我尝试使用Web服务时,我得到以下异常。 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. 我删除了使用并在服务客户端上添加了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();
                }
            }

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. 但似乎你需要更好的错误处理。

This error can also be caused by having zero methods tagged with the OperationContract attribute. 使用OperationContract属性标记零方法也可能导致此错误。 This was my problem when building a new service and testing it a long the way. 在构建新服务并对其进行长期测试时,这是我的问题。

Instead of using the using statement, try running your code without it. 使用using语句,请尝试在没有它的情况下运行代码。

From

using(var client = new WCFClient())
{
    // ... code
}

to

var client = new WCFClient()

// ... code

Upon doing so, we were able to see that the original WCF Cannot be used for communication because it is in the Faulted state message was caused by the using() call itself. 在这样做时,我们能够看到原始WCF不能用于通信,因为它处于Faulted状态消息是由using()调用本身引起的。 Why? 为什么? Our code that was using the WCF client was passing in invalid credentials, and the server responded with an error and changing the state of the proxy to faulted. 我们使用WCF客户端的代码传递了无效凭据,服务器响应错误并将代理状态更改为出现故障。 The using() block, as we know , calls Dispose() on the object - in this case our WCF client. 正如我们所知using()块在对象上调用Dispose() - 在本例中是我们的WCF客户端。

Because the WCF client failed, and the WCF client was in a faulted state, calling Dispose() caused the error WCF Cannot be used for communication because it is in the Faulted state to be thrown. 由于WCF客户端发生故障,并且WCF客户端处于故障状态,因此调用Dispose()导致错误WCF无法用于通信,因为它处于Faulted状态而被抛出。

We were able to see this by wrapping the code that uses the WCF client in a try...catch block. 我们通过在try...catch块中包装使用WCF客户端的代码来看到这一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WCF错误通信对象System.ServiceModel.Channels.ServiceChanne不能用于通信,因为它处于Faulted状态 - WCF Error The communication object, System.ServiceModel.Channels.ServiceChanne, cannot be used for communication because it is in the Faulted state 通信对象System.ServiceModel.Channels.ServiceChannel无法用于通信,因为它处于故障状态 - The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state 通信对象System.ServiceModel.Channels.ServiceChannel无法用于通信,因为它处于故障状态 - The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state 通信对象System.ServiceModel.Channels.ServiceChannel不能用于通信,因为它处于Faulted状态 - The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state CommunicationObjectFaultedException-System.ServiceModel.Channels.ServiceChannel无法用于通信,因为它处于故障状态 - CommunicationObjectFaultedException - System.ServiceModel.Channels.ServiceChannel cannot be used for communication because it is in faulted state WCF故障状态 - WCF Faulted State InternalClientWebSocket实例不能用于通信,因为它已转换为“已中止”状态 - InternalClientWebSocket instance cannot be used for communication because it has been transitioned into the 'Aborted' state WCF应用程序托管服务故障状态异常? - WCF Application hosted service Faulted State exception? 处理持久性WCF客户端进入故障状态 - Handle persistent WCF client entering faulted state WCF服务客户端处于故障状态怎么办? - What to do with a WCF service client in faulted state?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM