{"id":158,"date":"2017-11-29T11:29:00","date_gmt":"2017-11-29T11:29:00","guid":{"rendered":"https:\/\/www.mainmind.com\/blog\/?p=158"},"modified":"2020-07-27T07:19:11","modified_gmt":"2020-07-27T07:19:11","slug":"depuracion-de-errores-en-servicios-wcf","status":"publish","type":"post","link":"https:\/\/www.mainmind.com\/blog\/depuracion-de-errores-en-servicios-wcf\/","title":{"rendered":"Depuraci\u00f3n de errores en servicios WCF"},"content":{"rendered":"<p>Windows Communication Foundation agrega eventos en el registro de Windows de manera predeterminada, por seguridad, depuraci&oacute;n, mantenibilidad&#8230; es posible utilizar mecanimos adicionales con las trazas.<\/p>\n<p>A&ntilde;adiendo la siguiente configuraci&oacute;n de diagn&oacute;stico en nuestro web.config o app.exe.config:<\/p>\n<pre class=\"brush:xml;auto-links:false;toolbar:false\" contenteditable=\"false\">&lt;configuration&gt;  \n   &lt;system.diagnostics&gt;  \n      &lt;sources&gt;  \n            &lt;source name=\"System.ServiceModel\"   \n                    switchValue=\"Information, ActivityTracing\"  \n                    propagateActivity=\"true\"&gt;  \n            &lt;listeners&gt;  \n               &lt;add name=\"traceListener\"   \n                   type=\"System.Diagnostics.XmlWriterTraceListener\"   \n                   initializeData= \"D:\\log\\registro.svclog\" \/&gt;  \n            &lt;\/listeners&gt;  \n         &lt;\/source&gt;  \n      &lt;\/sources&gt;  \n   &lt;\/system.diagnostics&gt;  \n&lt;\/configuration&gt;<\/pre>\n<p>Posible errores no visibles, dificiles de acotar o reproducir aparecen claros y detallados, hasta el m&aacute;s sencillo que se nos puede pasar por alto:<\/p>\n<pre class=\"brush:csharp;auto-links:false;toolbar:false\" contenteditable=\"false\">en System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String message, Type type)\n   en WriteresultadoOperacionToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )\n   en System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)\n   en System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)\n   en System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)\n   en System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)\n   en System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)\n   en System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)\n   en System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)\n   en System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)\n   en System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameter(XmlDictionaryWriter writer, PartInfo part, Object graph)\n   en System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)\n   en System.ServiceModel.Dispatcher.OperationFormatter.SerializeBodyContents(XmlDictionaryWriter writer, MessageVersion version, Object[] parameters, Object returnValue, Boolean isRequest)\n   en System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)\n   en System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)\n   en System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)\n   en System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)\n   en System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)\n   en System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message, Boolean shouldRecycleBuffer)\n   en System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)\n   en System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.SendReplyCore(Message message, TimeSpan timeout)\n   en System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.SendReply(Message message, TimeSpan timeout)\n   en System.ServiceModel.Channels.HttpRequestContext.OnReply(Message message, TimeSpan timeout)\n   en System.ServiceModel.Channels.RequestContextBase.Reply(Message message, TimeSpan timeout)\n   en System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Reply(MessageRpc&amp; rpc)\n<\/pre>\n<p>Se transforma en algo tal que as&iacute;:<\/p>\n<p><img decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/\/2017\/VisualStudio\/WCF_DEBUG_tracing.jpg\" alt=\"\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Referencias:<\/p>\n<ul style=\"list-style-type: square;\">\n<li>Configurando seguimiento: <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/framework\/wcf\/diagnostics\/tracing\/configuring-tracing\" target=\"_blank\" rel=\"noopener noreferrer\">enabling tracing<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/framework\/wcf\/configuration-editor-tool-svcconfigeditor-exe\" target=\"_blank\" rel=\"noopener noreferrer\">Editor gr&aacute;fico de configuraci&oacute;n WCF<\/a>: bindings, behaviors, services and diagnostics<br \/>NOTA: la ruta puede variar al ejecutable del SDK seg&uacute;n versi&oacute;n, por ejemplo <br \/><em>C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.6.2 Tools<\/em><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Windows Communication Foundation agrega eventos en el registro de Windows de manera predeterminada, por seguridad, depuraci&oacute;n, mantenibilidad&#8230; es posible utilizar mecanimos adicionales con las trazas. A&ntilde;adiendo la siguiente configuraci&oacute;n de diagn&oacute;stico en nuestro web.config o app.exe.config: &lt;configuration&gt; &lt;system.diagnostics&gt; &lt;sources&gt; &lt;source name=\u00bbSystem.ServiceModel\u00bb switchValue=\u00bbInformation, ActivityTracing\u00bb propagateActivity=\u00bbtrue\u00bb&gt; &lt;listeners&gt; &lt;add name=\u00bbtraceListener\u00bb type=\u00bbSystem.Diagnostics.XmlWriterTraceListener\u00bb initializeData= \u00abD:\\log\\registro.svclog\u00bb \/&gt; &lt;\/listeners&gt; &lt;\/source&gt; &lt;\/sources&gt; &lt;\/system.diagnostics&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[345,346,344,343],"class_list":["post-158","post","type-post","status-publish","format-standard","hentry","category-visual-studio","tag-debug","tag-depurar","tag-errores","tag-wcf"],"_links":{"self":[{"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":0,"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/posts\/158\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/categories?post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mainmind.com\/blog\/wp-json\/wp\/v2\/tags?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}