tag endpointbehaviors configuracion bindings basichttpsbinding wcf web-config ierrorhandler

endpointbehaviors - Cómo configurar web.config para WCF IErrorhandler



wcf service binding configuration (2)

Es un poco tarde, pero para otros usuarios aquí hay un mejor enfoque (en mi opinión) y el código anterior solo tiene que cambiarse un poco

Tu puedes cambiar:

public class WcfErrorServiceBehaviour : IServiceBehavior

a:

public class WcfErrorServiceBehaviourAttribute : Attribute, IServiceBehavior

Ahora puede usar esto como un atributo para su clase de servicio de esta manera:

[WcfErrorServiceBehaviour] [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)] public class MXServiceCommands : IMXServiceCommands { }

Espero que esto ayude a otros.

No puedo integrar IErrorHandler en mi proyecto con la web.config correcta

Tengo un WCF que funciona con éxito y que los clientes web están consumiendo en .net 4, pero al intentar configurar IErrorhandler como un registrador de errores global como un todo para todos mis métodos de servicio, las cosas fallan rápidamente, principalmente para hacer con la parte web.config ! Por favor ayuda.

Los tres servicios son: IReport, IServiceCustomer, IServiceUser

Implementado IErrorHandler en una clase separada llamada MyErrorClass.cs como esta:

namespace CustomerWcfService { public class WcfErrorHandler : IErrorHandler { /// <summary> /// Enables the creation of a custom <see cref="T:System.ServiceModel.FaultException`1"/> that is returned from an exception in the course of a service method. /// </summary> /// <param name="error">The <see cref="T:System.Exception"/> object thrown in the course of the service operation.</param><param name="version">The SOAP version of the message.</param><param name="fault">The <see cref="T:System.ServiceModel.Channels.Message"/> object that is returned to the client, or service, in the duplex case.</param> public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { // can create custom error messages here } /// <summary> /// Enables error-related processing and returns a value that indicates whether the dispatcher aborts the session and the instance context in certain cases. /// </summary> /// <returns> /// true if should not abort the session (if there is one) and instance context if the instance context is not <see cref="F:System.ServiceModel.InstanceContextMode.Single"/>; otherwise, false. The default is false. /// </returns> /// <param name="error">The exception thrown during processing.</param> public bool HandleError(Exception error) { // log error to database using legacy error handler ErrorHandler.LogError(error); // Let the other ErrorHandler do their jobs return true; } } public class WcfErrorServiceBehaviour : IServiceBehavior { /// <summary> /// Provides the ability to inspect the service host and the service description to confirm that the service can run successfully. /// </summary> /// <param name="serviceDescription">The service description.</param><param name="serviceHostBase">The service host that is currently being constructed.</param> public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { } /// <summary> /// Provides the ability to pass custom data to binding elements to support the contract implementation. /// </summary> /// <param name="serviceDescription">The service description of the service.</param><param name="serviceHostBase">The host of the service.</param><param name="endpoints">The service endpoints.</param><param name="bindingParameters">Custom objects to which binding elements have access.</param> public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters) { } /// <summary> /// Provides the ability to change run-time property values or insert custom extension objects such as error handlers, message or parameter interceptors, security extensions, and other custom extension objects. /// </summary> /// <param name="serviceDescription">The service description.</param><param name="serviceHostBase">The host that is currently being built.</param> public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { var handler = new WcfErrorHandler(); foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers) { dispatcher.ErrorHandlers.Add(handler); } } } public class WcfErrorHandlerBehaviour : BehaviorExtensionElement { /// <summary> /// Creates a behavior extension based on the current configuration settings. /// </summary> /// <returns> /// The behavior extension. /// </returns> protected override object CreateBehavior() { return new WcfErrorServiceBehaviour(); } /// <summary> /// Gets the type of behavior. /// </summary> /// <returns> /// A <see cref="T:System.Type"/>. /// </returns> public override Type BehaviorType { get { return typeof (WcfErrorServiceBehaviour); } } } }

¿Cómo debería ser el web.config ya que he probado un millón de combinaciones de varios tutoriales y respuestas en la red pero no funciona! Así es como se ve el extracto de trabajo original de web.config cuando no estoy involucrando IErrorHandler

<system.serviceModel> <behaviors> <serviceBehaviors> <behavior> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true" /> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> </system.webServer>

Por favor, ¿alguien puede enviar este novato de WCF a la web.config corregida, como sigo eliminando y tratando de nuevo y no llegar a ninguna parte (he perdido tantos días en esto) :(


<system.serviceModel> <behaviors> <serviceBehaviors> <behavior> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true" /> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="true" /> <errorHandler/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> <extensions> <behaviorExtensions> <add name="errorHandler" type="CustomerWcfService.WcfErrorHandlerBehaviour, CustomerWcfService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> </behaviorExtensions> </extensions> </system.serviceModel>

Y luego aplique su comportamiento al servicio que desea que se aplique.

Editar:

perdón por la señorita, pero en realidad necesita eliminar cualquier salto de línea y cualquier espacio en blanco adicional en el nombre del tipo en la definición de extensión (error WCF anterior que le obliga a utilizar la cadena de nombre completo en la declaración de tipo de extensión).