Cuando intento usar un servicio web obtengo la siguiente excepción. Mi pregunta principal es ¿cuándo ocurre esta excepción? en el servidor o cliente? ¿Dónde está el error? ¿El servidor lanza esto para una amplia gama de fallas?WCF No se puede utilizar para la comunicación porque está en el estado Faulted
hice algunos cambios en mi propia que parece funcionar
En realidad funciona ahora. Quité el uso y agregué la limpieza de som en el cliente de servicio.
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();
}
}
Esta fue la excepción:
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)
La pila de llamadas de excepción, de hecho, le dice mucho a lo que debe prestar atención. Por ejemplo, Eliminar llamadas Cerrar. Por lo tanto, si el proxy ya está en estado Faulted, solo puede llamar Abort, no Close ni Dispose. Afortunadamente, descubres el cambio necesario. De hecho, Microsoft tiene un buen artículo que hace hincapié en qué tipo de patrón de llamadas se recomienda, http://msdn.microsoft.com/en-us/library/aa355056.aspx –
Mire también aquí http: // stackoverflow. com/questions/2763592/the-communication-object-system-servicemodel-channels-servicechannel-can-be –
También obtuve exactamente esta excepción no porque se trata de la excepción, sino simplemente por tratar de devolver 'DataTable' sin' TableName' establecido. Ver http://stackoverflow.com/questions/12702/returning-datatables-in-wcf-net –