<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog de Oxxigeno &#187; Desarrollo</title>
	<atom:link href="http://www.oxxigeno.com/blog/categoria/areas/desarrollo/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.oxxigeno.com/blog</link>
	<description>Blog corporativo de Oxxigeno</description>
	<lastBuildDate>Tue, 23 Feb 2010 10:11:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>El Armario de la Tele</title>
		<link>http://www.oxxigeno.com/blog/2010/02/el-armario-de-la-tele/</link>
		<comments>http://www.oxxigeno.com/blog/2010/02/el-armario-de-la-tele/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 22:28:54 +0000</pubDate>
		<dc:creator>jpardo</dc:creator>
				<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[Diseño]]></category>
		<category><![CDATA[Sistemas]]></category>
		<category><![CDATA[eCommerce]]></category>

		<guid isPermaLink="false">http://www.oxxigeno.com/blog/?p=744</guid>
		<description><![CDATA[El pasado mes de diciembre vio la luz uno de los proyectos más interesantes en los que hemos estado implicados durante el último año. Es posible que ya hayais oido hablar de él, o incluso que hayais visto algún anuncio en TV. Estamos hablando de El Armario de la Tele.

Se trata de un eCommerce de [...]]]></description>
			<content:encoded><![CDATA[<p>El pasado mes de diciembre vio la luz <strong>uno de los proyectos más interesantes</strong> en los que hemos estado implicados durante el último año. Es posible que ya hayais oido hablar de él, o incluso que hayais visto algún anuncio en TV. Estamos hablando de <a href="http://www.elarmariodelatele.com/">El Armario de la Tele</a>.</p>
<p><img class="aligncenter size-full wp-image-747" title="El Armario de la Tele" src="http://www.oxxigeno.com/blog/wp-content/uploads/2010/02/EAT_red1.jpg" alt="El Armario de la Tele" width="500" height="311" /></p>
<p>Se trata de un eCommerce de moda con una característica que lo hace único: <strong>los productos que se ofrecen en la tienda han aparecido en series o programas de televisión</strong>. Así, se puede buscar la ropa que ha aparecido en &#8220;Sé lo que hicisteis&#8221;, o la que ha vestido una presentadora de televisión o nuestro actor favorito. Por ahora El Armario tiene <strong>acuerdos comerciales con <a href="http://www.elarmariodelatele.com/antena-3">Antena 3</a>, <a href="http://www.elarmariodelatele.com/la-sexta">La Sexta</a> y <a href="http://www.elarmariodelatele.com/cuatro">Cuatro</a></strong>, y con <strong>más de 50 marcas de moda</strong>.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="385" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/h3jJg_OtF-o&amp;hl=es_ES&amp;fs=1&amp;rel=0" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="480" height="385" src="http://www.youtube.com/v/h3jJg_OtF-o&amp;hl=es_ES&amp;fs=1&amp;rel=0" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>El proyecto arrancó el pasado mes de Junio como una iniciativa de la consultora estratégica <a title="Bufete de Marketing" href="http://www.bufetedemarketing.com/">Bufete de Marketing</a>, la empresa de estilismo <a href="http://www.tvist.es/">TvisT</a> y la agencia de publicidad <a title="DoubleYou" href="http://www.doubleyou.com/">DoubleYou</a>. Oxxigeno fue seleccionado como <strong>proveedor tecnológico </strong>para la puesta en marcha del proyecto. Han sido unos meses de trabajo duro para llegar a las fechas previstas, pero estamos bastante satisfechos con el resultado.</p>
<p>Algunas de las tareas que hemos realizado en estos meses:</p>
<ul>
<li>En colaboración con DoubleYou, realizamos el <a href="http://www.oxxigeno.com/servicios/#diseno-visual-y-de-interaccion"><strong>diseño de interacción</strong></a> del sitio, tanto de la tienda como del backoffice.</li>
<li>Diseño del<strong> proceso de compra</strong>.</li>
<li><strong>Maquetación </strong>XHTML/CSS.</li>
<li>Definición de la <a href="http://www.oxxigeno.com/servicios/#arquitectura-tecnologica-y-de-sistemas"><strong>arquitectura tecnológica.</strong></a></li>
<li><a href="http://www.oxxigeno.com/servicios/#desarrollo-mantenimiento-de-aplicaciones"><strong>Desarrollo tecnológico</strong></a> completo de la plataforma.</li>
<li>Implementación del <strong>backoffice </strong>y de los mecanismos de administración, métricas, gestión de contenidos, sincronización con socio logístico, pasarela de pagos, etc.</li>
<li><strong>Soporte </strong>técnico, <strong>monitorización </strong>del rendimiento de la plataforma.</li>
<li><strong>Mantenimiento </strong>correctivo y adaptativo.</li>
</ul>
<p>Por ahora, la acogida de <a href="http://www.elarmariodelatele.com">El Armario de la Tele</a> ha sido estupenda. El proyecto aún está arrancando y le queda mucha vida por delante. En los próximos meses <strong>El Armario no dejará de crecer y mejorar, ¡estad atentos!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oxxigeno.com/blog/2010/02/el-armario-de-la-tele/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>El área de servicios de desarrollo de software de Oxxigeno ya es CMMI nivel 2</title>
		<link>http://www.oxxigeno.com/blog/2009/08/el-area-de-servicios-de-desarrollo-de-software-de-oxxigeno-ya-es-cmmi-nivel-2/</link>
		<comments>http://www.oxxigeno.com/blog/2009/08/el-area-de-servicios-de-desarrollo-de-software-de-oxxigeno-ya-es-cmmi-nivel-2/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 18:15:40 +0000</pubDate>
		<dc:creator>gruiz</dc:creator>
				<category><![CDATA[Calidad]]></category>
		<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[Metodología]]></category>

		<guid isPermaLink="false">http://www.oxxigeno.com/blog/?p=680</guid>
		<description><![CDATA[Continuando con los pasos planificados para mejorar los procesos de nuestros servicios de desarrollo, como se detalló en el anterior post, solicitamos una evaluación intermedia para conocer la situación en la que nos encontrábamos.  Para realizar esta evaluación intermedia, solicitamos a una consultora externa que  validase nuestros procesos y su implantación mediante un SCAMPI clase [...]]]></description>
			<content:encoded><![CDATA[<p>Continuando con los pasos planificados para mejorar los procesos de nuestros servicios de desarrollo, como se detalló en el anterior post, solicitamos una evaluación intermedia para conocer la situación en la que nos encontrábamos.  Para realizar esta evaluación intermedia, solicitamos a una consultora externa que  validase nuestros procesos y su implantación mediante un <strong>SCAMPI clase B.</strong></p>
<p>El método <strong>SCAMPI</strong> (<em>Standard CMMI Appraisal Method for Process Improvement</em>) es un proceso diseñado y desarrollado por el <strong><a href="http://www.sei.cmu.edu/">SEI</a></strong>, <em>Software Engineering Institute</em>, para evaluar la adherencia de los procesos implantados por una organización al modelo <strong>CMMI</strong>. Hay tres variantes de <strong>SCAMPI</strong>:</p>
<ul>
<li><strong>clase C</strong>, que consiste en una prueba de enfoque de los procesos existentes en la organización</li>
<li><strong>clase B, </strong>en el que se valida el despliegue o puesta en marcha de los procesos implementados</li>
<li><strong>clase A, </strong>que debe ser realizado por un <a href="http://partner-directory.sei.cmu.edu/search_auth.cfm/" target="_blank"><strong>Lead Appraiser</strong></a> (Líder-Evaluador SCAMPI) autorizado por el SEI y que consiste en la rigurosa evaluación de la institucionalización con la posibilidad de obtener un nivel de madurez.</li>
</ul>
<p>Los resultados del SCAMPI B realizado en Oxxigeno fueron positivos y nos dieron la confianza suficiente para afrontar la fase final del proyecto, <strong>el SCAMPI A</strong>.</p>
<p>Nuestros siguientes pasos fueron ponernos en contacto con la evaluadora autorizada por el SEI que lideró nuestro SCAMPI A, y comenzar a generar un plan para definir los siguientes factores:</p>
<ul>
<li><strong>Equipo del SCAMPI</strong>: compuesto por 5 miembros: 2 internos de Oxxigeno, 2 externos y el líder-evaluador. La intervención de recursos internos y externos facilitó el trabajo del equipo, ya que aportó distintas visiones de los procesos generados</li>
<li><strong>Fechas</strong>: se planificaron las fechas de los distintos hitos del SCAMPI A</li>
<li><strong>Actividades: </strong>se fijaron las actividades que tendrían lugar durante cada fase para planificarlas adecuadamente</li>
<li><strong>Riesgos</strong>: se tomaron en cuenta los distintos riesgos que podrían afectar al correcto desarrollo del SCAMPI A</li>
</ul>
<p>Todo SCAMPI A consta de dos fases:</p>
<ul>
<li><strong>Revisión documental (<em>Readiness Review</em>)</strong>: durante esta primera parte el equipo revisa las evidencias presentadas, los procesos de la organización, la aplicación de los procesos a los proyectos evaluados, la documentación generada, las herramientas utilizadas para implantar los procesos&#8230; De esta fase saldrá una primera visión del estado que permitirá minimizar riesgos</li>
<li><strong>Entrevistas (<em>On site</em>)</strong>: en esta segunda fase tienen lugar las entrevistas a distintos roles de los proyectos seleccionados para verificar la implantación de los procesos definidos en los proyectos</li>
</ul>
<p><img class="aligncenter size-full wp-image-699" src="http://www.oxxigeno.com/blog/wp-content/uploads/2009/08/cifras7.PNG" alt="cifras" width="546" height="212" /></p>
<p>Siguiendo la planificación establecida, durante los meses de mayo y junio tuvieron lugar las dos fases del <strong>SCAMPI A</strong> en Oxxigeno; los objetivos marcados fueron los siguientes:</p>
<ul>
<li>Comparar nuestros procesos con el modelo</li>
<li>Identificar las debilidades y oportunidades de mejora de cada área para efectuar las modificaciones necesarias</li>
<li>Enmarcar las debilidades detectadas dentro de la unidad organizacional para continuar mejorando la calidad de productos y procesos</li>
<li>Identificar las mejores prácticas y fortalezas de cada área para aplicarlas al resto de áreas</li>
</ul>
<p>Tras efectuar las entrevistas correspondientes, analizar los 19 objetivos y 108 prácticas a satisfacer y revisar las 512 evidencias presentadas obtuvimos los siguientes resultados por cada área de proceso:</p>
<p><img class="aligncenter size-full wp-image-682" src="http://www.oxxigeno.com/blog/wp-content/uploads/2009/08/nivel2.PNG" alt="nivel2" width="546" height="312" /></p>
<p>Con todas las áreas de proceso aplicables satisfechas y tras la revisión por parte del SEI, el pasado mes se publicaron los <strong><a href="http://sas.sei.cmu.edu/pars/pars_detail.aspx?a=12955" target="_blank">resultados de nuestro SCAMPI</a></strong> que han sido positivos, por lo que el <strong>área de servicios de desarrollo de software de Oxxigeno ya es nivel 2 de CMMI!</strong></p>
<p>Ahora estamos inmersos en la optimización de los procesos que hemos creado para continuar con la <strong>mejora continua</strong> que nos planteamos al comenzar la implantación del modelo <strong>CMMI</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oxxigeno.com/blog/2009/08/el-area-de-servicios-de-desarrollo-de-software-de-oxxigeno-ya-es-cmmi-nivel-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CMMI: Hacia la mejora de procesos. ¿Estamos preparados?</title>
		<link>http://www.oxxigeno.com/blog/2009/07/cmmi-hacia-la-mejora-de-procesos-%c2%bfestamos-preparados/</link>
		<comments>http://www.oxxigeno.com/blog/2009/07/cmmi-hacia-la-mejora-de-procesos-%c2%bfestamos-preparados/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 09:40:34 +0000</pubDate>
		<dc:creator>gruiz</dc:creator>
				<category><![CDATA[Calidad]]></category>
		<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[Metodología]]></category>

		<guid isPermaLink="false">http://www.oxxigeno.com/blog/?p=625</guid>
		<description><![CDATA[Para afianzar el éxito en los proyectos y la confianza de nuestros clientes, en Oxxigeno nos planteamos la necesidad de mejorar nuestra metodología y crear procesos avalados por alguna entidad o institución que nos permitiesen incrementar y consolidar nuestra calidad trabajando en un entorno de mejora continua.
Los objetivos que nos marcamos para afrontar el proyecto [...]]]></description>
			<content:encoded><![CDATA[<p>Para afianzar el éxito en los proyectos y la confianza de nuestros clientes, en Oxxigeno nos planteamos la necesidad de mejorar nuestra metodología y crear procesos avalados por alguna entidad o institución que nos permitiesen <strong>incrementar y consolidar nuestra calidad trabajando en un entorno de mejora continua</strong>.</p>
<p>Los objetivos que nos marcamos para afrontar el proyecto de mejora son los siguientes:</p>
<ul>
<li><strong>Disminuir costes</strong> en el proceso de desarrollo</li>
<li>Implantar una <strong>metodología de desarrollo común</strong> basada en el uso de herramientas</li>
<li>Continuar produciendo desarrollos de <strong>alta calidad</strong></li>
<li>Aumentar la <strong>fidelidad </strong>de nuestros clientes</li>
<li>Incrementar nuestra <strong>eficiencia</strong></li>
</ul>
<p>Tras analizar los distintos modelos existentes de calidad y mejora de procesos, seleccionamos como referencia el <strong>modelo CMMI</strong>, ya que proporciona a las organizaciones que lo implantan un marco que facilita la mejora continua y la habilidad para desarrollar y mantener sus productos y servicios.</p>
<p><span id="more-625"></span></p>
<p><a title="CMMI" href="http://www.sei.cmu.edu/cmmi/">CMMI</a> es un modelo de mejora de procesos desarrollado por el <a title="SEI" href="http://www.sei.cmu.edu">SEI</a> (Software Engineering Institute). Este instituto, que actualmente está financiado por el departamento de Defensa de EEUU y administrado por la Universidad Carnegie Mellon, se fundó por el Congreso de Estados Unidos en 1974 para <strong>desarrollar modelos de evaluación y mejora</strong>, ya que era necesario dar respuesta a los problemas que generaba la programación e integración de los subsistemas de software en la construcción de complejos sistemas militares.</p>
<p>CMMI establece <strong>5 niveles de madurez</strong> y <strong>22 áreas de proceso</strong> para clasificar a las organizaciones dentro de dos representaciones, <strong>escalonada </strong>y <strong>continua</strong>.</p>
<p>Cada organización puede optar por la que se adapte mejor a sus características y prioridades de mejora; en Oxxigeno <strong>optamos por la representación escalonada</strong> por adecuarse a los objetivos planteados.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-631" src="http://www.oxxigeno.com/blog/wp-content/uploads/2009/07/cmmi.jpg" alt="cmmi" width="562" height="268" /></p>
<p>Decidimos comenzar por el nivel 2 por su orientación a la gestión de proyectos. Las <strong>áreas de proceso</strong> contempladas en este nivel son las siguientes:</p>
<ul>
<li>Planificación de proyectos</li>
<li>Seguimiento y control de procesos</li>
<li>Gestión de requisitos</li>
<li>Aseguramiento de la calidad de procesos y productos</li>
<li>Medición y análisis</li>
<li>Gestión de la configuración</li>
<li>Gestión de acuerdos con proveedores</li>
</ul>
<p>En el comienzo de la implantación se realizó una <strong>evaluación inicial</strong> para detectar la situación de partida en la que nos encontrábamos y, posteriormente, se formó un equipo con distintos perfiles para analizar los resultados obtenidos y comenzar a trabajar en la implantación de procesos comunes para el área de servicios de desarrollo.</p>
<p>En Oxxigeno, decidimos afrontar el desarrollo y la implantación de los procesos tomando como pilares fundamentales las siguientes características:</p>
<ul>
<li>Utilización de <strong>herramientas ya conocidas </strong>por nuestros equipos: de este modo, el cambio no sería tan costoso y aprovecharíamos los conocimientos existentes.</li>
<li>Implantación de una <strong>metodología común basada en los métodos y procesos que ya se estaban utilizando</strong>: los integrantes de los equipos de desarrollo ya tenían unos procesos y seguían una metodología; el propósito no era modificar dicha metodología ni inventar nuevos procesos, la meta era desarrollar una base común de procesos utilizable por todos.</li>
<li><strong>Apoyo incondicional de Dirección</strong>: desde el comienzo, la dirección de Oxxigeno consideró la mejora de procesos como un proyecto estratégico beneficioso para toda la organización. Por ese motivo nos apoyó durante todas las fases de la implantación.</li>
<li><strong>Distintas visiones</strong> en nuestro equipo de mejora de procesos: para ello, el equipo se compuso por personas de distintos perfiles que pudiésemos dar diferentes puntos de vista sobre la metodología a implantar.</li>
<li><strong>Implicación de todos los integrantes de Oxxigeno</strong>: durante todas las fases del proyecto celebramos reuniones con los jefes de proyecto, gerentes y distintos roles de la organización para revisar el avance del proyecto y recoger sugerencias y peticiones.</li>
</ul>
<p>Tras cinco meses de trabajo, desarrollo e implantación en proyectos decidimos pasar a la siguiente fase. Solicitamos una<strong> evaluación intermedia</strong> para conocer el estado en el que estábamos y el grado de avance de consecución de los objetivos planteados. En los próximos días hablaremos del resultado de dicha evaluación y cuáles fueron nuestros siguientes pasos.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oxxigeno.com/blog/2009/07/cmmi-hacia-la-mejora-de-procesos-%c2%bfestamos-preparados/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Evento: Llega la web comercialmente inteligente</title>
		<link>http://www.oxxigeno.com/blog/2009/06/evento-llega-la-web-comercialmente-inteligente/</link>
		<comments>http://www.oxxigeno.com/blog/2009/06/evento-llega-la-web-comercialmente-inteligente/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 09:01:40 +0000</pubDate>
		<dc:creator>Oxxigeno</dc:creator>
				<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[Diseño]]></category>
		<category><![CDATA[Innovación]]></category>
		<category><![CDATA[Oxxigeno]]></category>

		<guid isPermaLink="false">http://www.oxxigeno.com/blog/?p=600</guid>
		<description><![CDATA[Estamos orgullos de comunicar que estaremos en las jornadas &#8220;Llega la web comercialmente inteligente&#8221;, que tendrán lugar esta semana en Barcelona y Madrid.
Compartiremos programa con buenos amigos de Multiplica y T2O Media, empresas con las que hemos trabajado y con las que nos alineamos en una misma visión de la web.
Las jornadas son gratuitas y [...]]]></description>
			<content:encoded><![CDATA[<p>Estamos orgullos de comunicar que estaremos en las jornadas &#8220;Llega la web comercialmente inteligente&#8221;, que tendrán lugar esta semana en Barcelona y Madrid.</p>
<p><span id="more-600"></span>Compartiremos programa con buenos amigos de <a title="Multiplica" href="http://www.multiplica.com/">Multiplica</a> y <a title="T2O" href="http://www.t2o.es/">T2O Media</a>, empresas con las que hemos trabajado y con las que nos alineamos en una misma visión de la web.</p>
<p>Las jornadas son gratuitas y tendrán lugar en <strong>Barcelona </strong>el <strong>martes 16 de junio </strong>de <strong>10 a 12:30</strong> en el <a title="Dirección del hotel" href="http://maps.google.es/maps?f=q&amp;source=s_q&amp;hl=es&amp;geocode=&amp;q=Hotel+U232+barcelona&amp;sll=40.430616,-3.659005&amp;sspn=0.017444,0.038624&amp;ie=UTF8&amp;ll=41.391942,2.148943&amp;spn=0.035994,0.077248&amp;z=14&amp;iwloc=A">Hotel U232</a> y en <strong>Madrid </strong>el <strong>miércoles 17 de junio</strong> de <strong>9 a 11:30</strong> en el <a title="Dirección del hotel" href="http://maps.google.es/maps?f=q&amp;source=s_q&amp;hl=es&amp;geocode=&amp;q=De+Las+Letras+Hotel+%26+Restaurant&amp;sll=40.419639,-3.703616&amp;sspn=0.011778,0.026844&amp;g=Gran+V%C3%ADa,+11,+madrid&amp;ie=UTF8&amp;z=15&amp;iwloc=A">Hotel de la Letras</a>.</p>
<p>Aún nos queda alguna plaza de última hora. Si estás interesado, contacta con nosotros en <a href="mailto:evento@oxxigeno.com">evento@oxxigeno.com</a></p>
<p><img class="alignnone size-full wp-image-604" title="La web comercialmente inteligente" src="http://www.oxxigeno.com/blog/wp-content/uploads/2009/06/evento1.png" alt="La web comercialmente inteligente" width="498" height="1052" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oxxigeno.com/blog/2009/06/evento-llega-la-web-comercialmente-inteligente/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Buenas Prácticas en .NET: Uso estructurado del fichero de configuración</title>
		<link>http://www.oxxigeno.com/blog/2009/06/buenas-practicas-en-net-uso-estructurado-del-fichero-de-configuracion/</link>
		<comments>http://www.oxxigeno.com/blog/2009/06/buenas-practicas-en-net-uso-estructurado-del-fichero-de-configuracion/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 17:08:02 +0000</pubDate>
		<dc:creator>ivinuales</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[app.config]]></category>
		<category><![CDATA[ascx]]></category>
		<category><![CDATA[aspx]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[web.config]]></category>

		<guid isPermaLink="false">http://www.oxxigeno.com/blog/?p=467</guid>
		<description><![CDATA[Una práctica habitual en desarrollos asp net es utilizar el fichero de configuración (o el app config en aplicativos de escritorio) como almacén de valores configurables que luego se utilizarán en el aplicativo para uno u otro propósito.
Lo que en principio se nos antoja como una buena práctica, en la mayoría de las ocasiones, debido [...]]]></description>
			<content:encoded><![CDATA[<p>Una práctica habitual en desarrollos asp net es utilizar el fichero de configuración (o el app config en aplicativos de escritorio) como almacén de valores configurables que luego se utilizarán en el aplicativo para uno u otro propósito.</p>
<p>Lo que en principio se nos antoja como una buena práctica, en la mayoría de las ocasiones, debido a una utilización mal estructurada del fichero de configuración, se convierte en una lista incontrolable y sin organización alguna de entradas en el nodo <em>appSettings</em>.</p>
<p>Para evitar esto existe una solución alternativa, más elegante, más clara y, más optima. Las clases <em>ConfigurationSection</em>, <em>ConfigurationElement </em>y <em>ConfigurationElementCollection </em>permiten <strong>definir secciones, elementos y colecciones de elementos en el fichero de configuración</strong> y utilizarlas como cualquier otro objeto en nuestro aplicativo.</p>
<p>Vamos a definir una pequeña sección en el fichero de configuración y comentamos un poquito cómo realizarla.</p>
<p><span id="more-467"></span><br />
La clase <em>EjemploData </em>heredará de <em>ConfigurationElement </em>y tendrá dos propiedades <em>Name </em>y <em>PropiedadBooleana</em>, de tipo string y bool respectivamente. Las propiedades de ambas deberán tener el atributo <em>ConfigurationProperty </em>con el nombre que tomará en el fichero de configuración, su valor por defecto (si queremos especificarlo) y si es obligatoria.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> EjemploData <span style="color: #008000;">:</span> ConfigurationElement
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080;">#region Public Properties</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> NamePropertyName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;name&quot;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>ConfigurationProperty<span style="color: #000000;">&#40;</span>NamePropertyName, IsRequired <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Name
        <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span><span style="color: #000000;">&#91;</span>NamePropertyName<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">this</span><span style="color: #000000;">&#91;</span>NamePropertyName<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> PropiedadBooleanaPropertyName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;propiedadBooleana&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#91;</span>ConfigurationProperty<span style="color: #000000;">&#40;</span>PropiedadBooleanaPropertyName, DefaultValue <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;true&quot;</span>, IsRequired <span style="color: #008000;">=</span> <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> PropiedadBooleana
        <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">bool</span><span style="color: #000000;">&#41;</span><span style="color: #0600FF;">this</span><span style="color: #000000;">&#91;</span>PropiedadBooleanaPropertyName<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">this</span><span style="color: #000000;">&#91;</span>PropiedadBooleanaPropertyName<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
    <span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<p>Crearemos una clase <em>EjemploDataCollection </em>que herede de <em>ConfigurationElementCollection</em>, tal y como se muestra, no requiere mucha explicación</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> EjemploDataCollection <span style="color: #008000;">:</span> ConfigurationElementCollection
<span style="color: #000000;">&#123;</span>
<span style="color: #008080;">#region ConfigurationElementCollection Members</span>
&nbsp;
<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> ConfigurationElement CreateNewElement<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> EjemploData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">object</span> GetElementKey<span style="color: #000000;">&#40;</span>ConfigurationElement element<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>EjemploData<span style="color: #000000;">&#41;</span>element<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Name</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> EjemploData <span style="color: #0600FF;">this</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">int</span> index<span style="color: #000000;">&#93;</span>
<span style="color: #000000;">&#123;</span>
get
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>EjemploData<span style="color: #000000;">&#41;</span>BaseGet<span style="color: #000000;">&#40;</span>index<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
set
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>BaseGet<span style="color: #000000;">&#40;</span>index<span style="color: #000000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
BaseRemoveAt<span style="color: #000000;">&#40;</span>index<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
BaseAdd<span style="color: #000000;">&#40;</span>index, value<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008080;">#endregion</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<p>Finalmente, crearemos la clase que nos permita manejar este tipo de objetos. Esta clase debe heredar de <em>ConfigurationSection</em>, la cual nos servirá para marcar el ámbito en el cual obtendremos los valores dentro del fichero de configuración. Debe tener:</p>
<ul>
<li>Una constante pública que nos indique cómo llegar a la sección adecuada del fichero de configuración.</li>
<li>Constantes privadas que nos marquen cómo se llamarán los atributos.</li>
<li>Nodos hijos que podremos definir en el fichero de configuración</li>
<li>Sus respectivas propiedades públicas que nos permitirán utilizarlas en cualquier parte de nuestro aplicativo.</li>
</ul>
<p>En nuestro ejemplo definiremos la seccion como “<em>oxxigeno/ejemploSettings</em>”, lo que significa que en el fichero de configuración tendremos que definir un nodo <em>oxxigeno</em> y dentro uno <em>ejemploSettings</em>.</p>
<p>Queremos que exista una atributo en el nodo <em>ejemploSettings</em>, para lo cual crearemos una constante privada que nos diga como debe llamarse, “<em>nuevaPropiedad</em>”, y una propiedad pública que nos permita recuperarlo del fichero de configuración y utilizarlo en el aplicativo. Para ello crearemos una propiedad normal que nos devolverá un objeto de tipo string y le establecemos un atributo a la propiedad de tipo <em>ConfigurationProperty</em><strong>, </strong>que indique cómo se va a llamar ese atributo en el fichero de configuración y si es obligatorio o no que exista.</p>
<p>Además nos interesa que bajo el nodo <em>ejemploSettings </em>exista una colección de nodos del mismo tipo (en nuestro caso <em>EjemploData</em>). Para ello procederemos igual que para la propiedad actual, pero definiremos su salida como <em>EjemploDataCollection</em><strong>, </strong>y le agregaremos el atributo <em>ConfigurationCollection</em><strong> </strong>pasándole como parámetro el tipo de objetos que se coleccionarán.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">sealed</span> <span style="color: #FF0000;">class</span> EjemploSettings <span style="color: #008000;">:</span> ConfigurationSection
<span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> SectionName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;oxxigeno/ejemploSettings&quot;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080;">#region Public Properties</span>
&nbsp;
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> NuevaPropiedadPropertyName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;nuevaPropiedad&quot;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>ConfigurationProperty<span style="color: #000000;">&#40;</span>NuevaPropiedadPropertyName, IsRequired <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> NuevaPropiedad
<span style="color: #000000;">&#123;</span>
get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span><span style="color: #000000;">&#91;</span>NuevaPropiedadPropertyName<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
set <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">this</span><span style="color: #000000;">&#91;</span>NuevaPropiedadPropertyName<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> ColeccionDeEjemploPropertyName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;coleccionDeEjemplo&quot;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>ConfigurationProperty<span style="color: #000000;">&#40;</span>ColeccionDeEjemploPropertyName, IsRequired <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span>, IsDefaultCollection <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #000000;">&#91;</span>ConfigurationCollection<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>EjemploData<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> EjemploDataCollection ColeccionDeEjemplo
<span style="color: #000000;">&#123;</span>
get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>EjemploDataCollection<span style="color: #000000;">&#41;</span><span style="color: #0600FF;">this</span><span style="color: #000000;">&#91;</span>ColeccionDeEjemploPropertyName<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008080;">#endregion</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<p>Así pues, para cargar datos en el fichero de configuración, debemos cargar la clase controladora (<em>EjemploSettings</em>) y montar el árbol de nodos que hemos definido en las clases.</p>
<p>Dentro del nodo <em>configurationSections </em>debemos crear un nodo <em>SectionGroup </em>como se muestra, y dentro un nodo <em>section</em>. Pueden existir múltiples nodos <em>sectionGroup </em>pero no con el mismo nombre. Cada nodo <em>sectionGroup </em>puede tener en su interior multiples nodos <em>section</em>.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sectionGroup</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;oxxigeno&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ejemploSettings&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Oxxigeno.Ejemplo.Configuration.EjemploSettings, Oxxigeno.Ejemplo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96df930e30970c00&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sectionGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</blockquote>
<p>Y despues creamos el árbol de nodos tal como lo hemos definido, quedaría algo así:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;oxxigeno<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ejemploSettings</span> <span style="color: #000066;">nuevaPropiedad</span>=<span style="color: #ff0000;">&quot;valorDeLaPropiedad&quot;</span>&amp;gt; </span>
<span style="color: #009900;">         <span style="color: #000000; font-weight: bold;">&lt;coleccionDeEjemplo</span>&amp;gt; <span style="color: #000000; font-weight: bold;">&lt;clear</span>/&amp;gt;</span>
<span style="color: #009900;">            <span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;nombreDeLaEntrada1&quot;</span> <span style="color: #000066;">propiedadBooleana</span>=<span style="color: #ff0000;">&quot;false&quot;</span> /&amp;gt; </span>
<span style="color: #009900;">            <span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;nombreDeLaEntrada2&quot;</span> <span style="color: #000066;">propiedadBooleana</span>=<span style="color: #ff0000;">&quot;true&quot;</span> /&amp;gt; </span>
<span style="color: #009900;">         <span style="color: #000000; font-weight: bold;">&lt;/coleccionDeEjemplo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ejemploSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/oxxigeno</span>&amp;gt;</span></pre></div></div>

</blockquote>
<p>La forma de recuperar estos valores sería la siguiente:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">EjemploSettings ejemploSettings <span style="color: #008000;">=</span> ConfigurationManager.<span style="color: #0000FF;">GetSection</span><span style="color: #000000;">&#40;</span>EjemploSettings.<span style="color: #0000FF;">SectionName</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> EjemploSettings<span style="color: #008000;">;</span>
<span style="color: #FF0000;">string</span> nuevaPropiedad <span style="color: #008000;">=</span> ejemploSettings.<span style="color: #0000FF;">NuevaPropiedad</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>EjemploData obj <span style="color: #0600FF;">in</span> ejemploSettings.<span style="color: #0000FF;">ColeccionDeEjemplo</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #FF0000;">string</span> nombre <span style="color: #008000;">=</span> obj.<span style="color: #0000FF;">Name</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">bool</span> propiedadBooleana <span style="color: #008000;">=</span> obj.<span style="color: #0000FF;">PropiedadBooleana</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<p>Considero que este método de utilización del fichero de configuración es:</p>
<ul>
<li><strong>Más útil</strong>: Los valores se encuentran parseados al tipo necesario, no se obtienen unicamente valores de tipo string como pasa si utilizamos AppSettings, lo cual facilita el trabajo del desarrollador.</li>
<li><strong>Más estructurado</strong>: Los valores dentro del fichero de configuración son facilmente localizables y, por lo tanto, modificables.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.oxxigeno.com/blog/2009/06/buenas-practicas-en-net-uso-estructurado-del-fichero-de-configuracion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nuevas Tecnologías &#8211; Windows Comunication Foundation</title>
		<link>http://www.oxxigeno.com/blog/2009/05/nuevas-tecnologias-windows-comunication-foundation/</link>
		<comments>http://www.oxxigeno.com/blog/2009/05/nuevas-tecnologias-windows-comunication-foundation/#comments</comments>
		<pubDate>Mon, 11 May 2009 13:55:17 +0000</pubDate>
		<dc:creator>ivinuales</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[.net 3.5]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[servicios]]></category>
		<category><![CDATA[wcf]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.oxxigeno.com/blog/?p=500</guid>
		<description><![CDATA[Este nuevo modulo incluido en el .NET Framework 3.5 establece un modelo de programación unificado para la implementación de sistemas distribuidos, especialmente orientado a servicios.
 Esta tecnología integra en una única metodología de programación las hasta ahora incompatibles COM+ (Serviced Components), .NET Remoting y Servicios Web.  Para ello, un servicio WCF debe definir una [...]]]></description>
			<content:encoded><![CDATA[<p>Este nuevo modulo incluido en el .NET Framework 3.5 establece un modelo de programación unificado para la implementación de sistemas distribuidos, especialmente orientado a servicios.</p>
<p><span id="more-500"></span> Esta tecnología integra en una única metodología de programación las hasta ahora incompatibles COM+ (Serviced Components), .NET Remoting y Servicios Web.  Para ello, un servicio WCF debe definir una serie de puntos de acceso (denominados EndPoints) que representan una puerta de entrada al servicio publicado, permitiendo así que un mismo servicio sea consultado mediante distintos tipos de comunicación.<br />
Los EndPoints deben presentar:</p>
<ul>
<li><strong>Dirección</strong>: representada por la clase EndPointAddress, indica dónde está la aplicación</li>
<li><strong>Enlace</strong>: representada por la clase Binding, indica cómo se puede accesar esa aplicación: Protocolo del transporte, Codificación y Seguridad.</li>
<li><strong>Contrato</strong>: representada por una clase con atributos de tipo <strong>ServiceContractAttribute</strong>, se trata de una definición de los datos que van a ser comunicados por el aplicativo.</li>
</ul>
<p>WCF utiliza mensajes SOAP para la comunicación de estos datos, siguiendo así un estándar de comunicación. Sin embargo, cuando se realiza una comunicación entre dos procesos WCF se optimiza esta comunicación, aplicando una codificación en formato binario para los mensajes SOAP. De esto podemos olvidarnos totalmente, ya que al fin podemos crear un servicio sin preocuparnos de cómo ni quién va a acceder a él.</p>
<p>Vayamos con un ejemplo y veamos si es realmente lo que nos venden. Creamos una interfaz y una entidad que serán las que utilizaremos para dar vida al servicio.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>ServiceContract<span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IExample
    <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
        <span style="color: #FF0000;">string</span> GetData<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> value<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
        ExampleType GetDataUsingDataContract<span style="color: #000000;">&#40;</span>ExampleType composite<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
        <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> GetNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #000000;">&#91;</span>DataContract<span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ExampleType
    <span style="color: #000000;">&#123;</span>
        <span style="color: #FF0000;">bool</span> _delete <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
        <span style="color: #FF0000;">string</span> _name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Name&quot;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>DataMember<span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> Delete
        <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _delete<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> _delete <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>DataMember<span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Name
        <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _name<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> _name <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<p>Los atributos DataContract y OperationContract son, para entendernos, los atributos que sustituyen a WebService y WebMethod. Mientras que los atributos DataContract y DataMember son los atributos que servirán para serializar las entidades que se publicarán a través del servicio.</p>
<p>Ahora, una vez creada la interfaz que publicará el servicio y la entidad, procedemos a implementar la funcionalidad del servicio.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ExampleService <span style="color: #008000;">:</span> IExample
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> GetData<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> value<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;You entered: {0}&quot;</span>, value<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> ExampleType GetDataUsingDataContract<span style="color: #000000;">&#40;</span>ExampleType composite<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>composite.<span style="color: #0000FF;">Delete</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                composite.<span style="color: #0000FF;">Name</span> <span style="color: #008000;">+=</span> <span style="color: #666666;">&quot; y Apellido&quot;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">return</span> composite<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> GetNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> lista <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                lista.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;nombre&quot;</span> <span style="color: #008000;">+</span> i.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">return</span> lista.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<p>Con esto ya tenemos el código necesario para crear un servicio con WCF. Nos falta darle posibles puntos de entrada, para poder publicarlo. Lo hacemos a través del web.config del servicio.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.serviceModel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Namespace.ExampleService&quot;</span> <span style="color: #000066;">behaviorConfiguration</span>=<span style="color: #ff0000;">&quot;Namespace.ExampleServiceBehavior&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- Service Endpoints --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;wsHttpBinding&quot;</span> <span style="color: #000066;">contract</span>=<span style="color: #ff0000;">&quot;Namespace.IExample&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;identity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dns</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;localhost&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/identity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/endpoint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;mex&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;mexHttpBinding&quot;</span> <span style="color: #000066;">contract</span>=<span style="color: #ff0000;">&quot;IMetadataExchange&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;behaviors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;serviceBehaviors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;behavior</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Namespace.ExampleServiceBehavior&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;serviceMetadata</span> <span style="color: #000066;">httpGetEnabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;serviceDebug</span> <span style="color: #000066;">includeExceptionDetailInFaults</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/behavior<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/serviceBehaviors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/behaviors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.serviceModel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</blockquote>
<p>Voy a intentar explicarlo de forma esquemática. Dentro de la etiqueta “services” creamos cada uno de los servicios que queramos publicar, mientras que dentro de la etiqueta “behaviors” definiremos diferentes comportamientos que podrán utilizarse en los servicios publicados.</p>
<p>Pero volvamos a la etiqueta “services”. Dentro de ella crearemos tantas etiquetas “service” como servicios queramos publicar. Cada una se define mediante nombre y comportamiento (“name” y “behaviorConfiguration”). Además debemos definir una serie de puntos de entrada (“endpoint”) con las propiedades “address”, “binding” y “contract”, y un nodo interno de tipo “identity” (como se ve en el código). Vamos con ellos:</p>
<ul>
<li>Etiqueta Service:
<ul>
<li>Address: Especificamos la URI, que puede estar como cadena vacía.</li>
<li>Binding: Especificamos el binding a utilizar, lo cual define el tipo de transporte, la seguridad y el encoding utilizado. Podemos utilizar un binding definido por nosotros.</li>
<li>Contract: Especifica la interfaz que define se publicará con el servicio.</li>
</ul>
</li>
<li>Etiqueta Behavior:
<ul>
<li>Name: Nombre del behavior, único en el web.config</li>
<li>ServiceMetadata: Especifica la publicación de los metadatos del servicio y de la información asociada.</li>
<li>ServiceDebug: Especifica las características de la información de depuración y de la ayuda para un servicio de la WCF.</li>
</ul>
</li>
</ul>
<p>Para una descripción más detallada podemos recurrir a la siguiente url de Microsoft: <a href="http://msdn.microsoft.com/en-us/library/ms733932.aspx">http://msdn.microsoft.com/en-us/library/ms733932.aspx</a></p>
<p>Respecto al cliente, su uso es tan sencillo como agregar la referencia al servicio a la solucion e invocarlo desde el código.</p>
<p>Al agregar la referencia al servicio podemos ver que el web.config ha sido modificado, añadiendo la configuracion necesaria para accesar dicho servicio. Veamos qué ha añadido:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.serviceModel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bindings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsHttpBinding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;binding</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;WSHttpBinding_IExample&quot;</span> <span style="color: #000066;">closeTimeout</span>=<span style="color: #ff0000;">&quot;00:01:00&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">openTimeout</span>=<span style="color: #ff0000;">&quot;00:01:00&quot;</span> <span style="color: #000066;">receiveTimeout</span>=<span style="color: #ff0000;">&quot;00:10:00&quot;</span> <span style="color: #000066;">sendTimeout</span>=<span style="color: #ff0000;">&quot;00:01:00&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">bypassProxyOnLocal</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">transactionFlow</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">hostNameComparisonMode</span>=<span style="color: #ff0000;">&quot;StrongWildcard&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">maxBufferPoolSize</span>=<span style="color: #ff0000;">&quot;524288&quot;</span> <span style="color: #000066;">maxReceivedMessageSize</span>=<span style="color: #ff0000;">&quot;65536&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">messageEncoding</span>=<span style="color: #ff0000;">&quot;Text&quot;</span> <span style="color: #000066;">textEncoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000066;">useDefaultWebProxy</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">allowCookies</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;readerQuotas</span> <span style="color: #000066;">maxDepth</span>=<span style="color: #ff0000;">&quot;32&quot;</span> <span style="color: #000066;">maxStringContentLength</span>=<span style="color: #ff0000;">&quot;8192&quot;</span> <span style="color: #000066;">maxArrayLength</span>=<span style="color: #ff0000;">&quot;16384&quot;</span></span>
<span style="color: #009900;">                        <span style="color: #000066;">maxBytesPerRead</span>=<span style="color: #ff0000;">&quot;4096&quot;</span> <span style="color: #000066;">maxNameTableCharCount</span>=<span style="color: #ff0000;">&quot;16384&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;reliableSession</span> <span style="color: #000066;">ordered</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">inactivityTimeout</span>=<span style="color: #ff0000;">&quot;00:10:00&quot;</span></span>
<span style="color: #009900;">                        <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">&quot;Message&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transport</span> <span style="color: #000066;">clientCredentialType</span>=<span style="color: #ff0000;">&quot;Windows&quot;</span> <span style="color: #000066;">proxyCredentialType</span>=<span style="color: #ff0000;">&quot;None&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">realm</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message</span> <span style="color: #000066;">clientCredentialType</span>=<span style="color: #ff0000;">&quot;Windows&quot;</span> <span style="color: #000066;">negotiateServiceCredential</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">algorithmSuite</span>=<span style="color: #ff0000;">&quot;Default&quot;</span> <span style="color: #000066;">establishSecurityContext</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/binding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsHttpBinding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bindings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;client<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;http://localhost:3153/ExampleService.svc&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;wsHttpBinding&quot;</span> <span style="color: #000066;">bindingConfiguration</span>=<span style="color: #ff0000;">&quot;WSHttpBinding_IExample&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">contract</span>=<span style="color: #ff0000;">&quot;ExampleServiceReference.IExample&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;WSHttpBinding_IExample&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;identity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dns</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;localhost&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/identity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/endpoint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/client<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.serviceModel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</blockquote>
<p>Él solo ha creado todo el arbol de etiquetas de configuracion necesario para acceder al servicio mediante el endpoint que deseemos. Si nos fijamos en la etiqueta “endpoint” dentro de “client” podemos ver cómo ha agregado la direccion del servicio, el tipo de binding, la configuracion del mismo, la interfaz que presenta y el nombre (que es lo que utilizaremos para crear el objeto client en código):</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">ExampleClient clientDefault <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ExampleClient<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;WSHttpBinding_IExample&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> namesDefault <span style="color: #008000;">=</span> clientDefault.<span style="color: #0000FF;">GetNames</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

</blockquote>
<p>Vamos a crear otro endpoint en el web.config del servicio y vamos a refrescar la referencia en el cliente para ver cómo cambia el web.config, añadiendo el nuevo endpoint y veremos cómo referenciarlo.  Agregamos dos endpoints:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;Soap11&quot;</span> <span style="color: #000066;">contract</span>=<span style="color: #ff0000;">&quot;Namespace.IExample&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;basicHttpBinding&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;Soap12&quot;</span> <span style="color: #000066;">contract</span>=<span style="color: #ff0000;">&quot;Namespace.IExample&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;wsHttpBinding&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

</blockquote>
<p>Y refrescamos la referencia al servicio en el cliente. Miramos el web.config y descubrimos que tenemos nuevas formas de acceder al servicio:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;http://localhost:3153/ExampleService.svc/Soap11&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;basicHttpBinding&quot;</span> <span style="color: #000066;">bindingConfiguration</span>=<span style="color: #ff0000;">&quot;BasicHttpBinding_IExample&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">contract</span>=<span style="color: #ff0000;">&quot;ExampleServiceReference.IExample&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;BasicHttpBinding_IExample&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;http://localhost:3153/ExampleService.svc/Soap12&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;wsHttpBinding&quot;</span> <span style="color: #000066;">bindingConfiguration</span>=<span style="color: #ff0000;">&quot;WSHttpBinding_IExample&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">contract</span>=<span style="color: #ff0000;">&quot;ExampleServiceReference.IExample&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;WSHttpBinding_IExample1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;identity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;userPrincipalName</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;ivinuales@oxxigeno-networks.spain&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/identity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/endpoint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</blockquote>
<p>Además, nos ha creado una nueva entrada dentro de bindings:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;basicHttpBinding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;binding</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;BasicHttpBinding_IExample&quot;</span> <span style="color: #000066;">closeTimeout</span>=<span style="color: #ff0000;">&quot;00:01:00&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">openTimeout</span>=<span style="color: #ff0000;">&quot;00:01:00&quot;</span> <span style="color: #000066;">receiveTimeout</span>=<span style="color: #ff0000;">&quot;00:10:00&quot;</span> <span style="color: #000066;">sendTimeout</span>=<span style="color: #ff0000;">&quot;00:01:00&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">allowCookies</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">bypassProxyOnLocal</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">hostNameComparisonMode</span>=<span style="color: #ff0000;">&quot;StrongWildcard&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">maxBufferSize</span>=<span style="color: #ff0000;">&quot;65536&quot;</span> <span style="color: #000066;">maxBufferPoolSize</span>=<span style="color: #ff0000;">&quot;524288&quot;</span> <span style="color: #000066;">maxReceivedMessageSize</span>=<span style="color: #ff0000;">&quot;65536&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">messageEncoding</span>=<span style="color: #ff0000;">&quot;Text&quot;</span> <span style="color: #000066;">textEncoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000066;">transferMode</span>=<span style="color: #ff0000;">&quot;Buffered&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">useDefaultWebProxy</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;readerQuotas</span> <span style="color: #000066;">maxDepth</span>=<span style="color: #ff0000;">&quot;32&quot;</span> <span style="color: #000066;">maxStringContentLength</span>=<span style="color: #ff0000;">&quot;8192&quot;</span> <span style="color: #000066;">maxArrayLength</span>=<span style="color: #ff0000;">&quot;16384&quot;</span></span>
<span style="color: #009900;">                        <span style="color: #000066;">maxBytesPerRead</span>=<span style="color: #ff0000;">&quot;4096&quot;</span> <span style="color: #000066;">maxNameTableCharCount</span>=<span style="color: #ff0000;">&quot;16384&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">&quot;None&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transport</span> <span style="color: #000066;">clientCredentialType</span>=<span style="color: #ff0000;">&quot;None&quot;</span> <span style="color: #000066;">proxyCredentialType</span>=<span style="color: #ff0000;">&quot;None&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">realm</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message</span> <span style="color: #000066;">clientCredentialType</span>=<span style="color: #ff0000;">&quot;UserName&quot;</span> <span style="color: #000066;">algorithmSuite</span>=<span style="color: #ff0000;">&quot;Default&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/binding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/basicHttpBinding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</blockquote>
<p>De tal forma que ahora en el código fuente podemos instanciarlo de 3 formas distintas:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">            ExampleClient clientDefault <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ExampleClient<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;WSHttpBinding_IExample&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> namesDefault <span style="color: #008000;">=</span> clientDefault.<span style="color: #0000FF;">GetNames</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            ExampleClient clientSOAP11 <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ExampleClient<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;BasicHttpBinding_IExample&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> namesSOAP11 <span style="color: #008000;">=</span> clientSOAP11.<span style="color: #0000FF;">GetNames</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            ExampleClient clientSOAP12 <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ExampleClient<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;WSHttpBinding_IExample1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> namesSOAP12 <span style="color: #008000;">=</span> clientSOAP12.<span style="color: #0000FF;">GetNames</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.oxxigeno.com/blog/2009/05/nuevas-tecnologias-windows-comunication-foundation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#, .NET 2.0 y procesamiento de CSV</title>
		<link>http://www.oxxigeno.com/blog/2009/04/generalizando-procesamiento-csv/</link>
		<comments>http://www.oxxigeno.com/blog/2009/04/generalizando-procesamiento-csv/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 14:06:41 +0000</pubDate>
		<dc:creator>ivinuales</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[ascx]]></category>
		<category><![CDATA[aspx]]></category>
		<category><![CDATA[microsoft]]></category>

		<guid isPermaLink="false">http://www.oxxigeno.com/blog/?p=483</guid>
		<description><![CDATA[Los ficheros csv son ficheros de texto que contienen valores separados por alguna caracter (en nuestro caso punto y coma) y agrupados en líneas. Es decir, cada línea podemos considerarla un conjunto de valores completo y podemos identificar a este conjunto de valores como una entidad.

Lo primero que debemos hacer es identificar esa entidad y [...]]]></description>
			<content:encoded><![CDATA[<p>Los ficheros csv son ficheros de texto que contienen valores separados por alguna caracter (en nuestro caso punto y coma) y agrupados en líneas. Es decir, cada línea podemos considerarla un conjunto de valores completo y podemos identificar a este conjunto de valores como una entidad.</p>
<p><span id="more-483"></span><br />
Lo primero que debemos hacer es <strong>identificar esa entidad y crear una clase para guardar esos datos</strong>. Después debemos tener algun mecanismo para rellenar esta clase con los valores de cada una de las filas (cada fila del fichero supondrá un objeto de ésta clase).</p>
<p>Pongamos un ejemplo.  Supongamos un fichero csv como el siguiente:</p>
<blockquote>
<pre>Edad; Nombre; Apellido
15; Pepito; Perez
57; Ernesto; Román
RowCount = 2</pre>
</blockquote>
<p>En ocasiones los csv traen una cabecera y/o un pie de fichero y en otras no, por lo que no podemos tratar de procesarlas siempre.</p>
<p>Vamos a empezar creando una clase entidad como la siguiente:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Edades
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">int</span> _edad<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> _nombre<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> _apellido<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Edad
    <span style="color: #000000;">&#123;</span>
        get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _edad<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        set <span style="color: #000000;">&#123;</span> _edad <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Nombre
    <span style="color: #000000;">&#123;</span>
        get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _nombre<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        set <span style="color: #000000;">&#123;</span> _nombre <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Apellido
    <span style="color: #000000;">&#123;</span>
        get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _apellido<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        set <span style="color: #000000;">&#123;</span> _apellido <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<p>Como vemos, se trata de una clase tonta con 3 atributos y sus 3 correspondientes propiedades publicas. En este ejemplo sería muy sencillo por cada fila crearnos un objeto y asignar a Edad el primer valor de la fila, a Nombre la segunda y a Apellido la tercera, serían 3 simples líneas. Sin embargo, a medida que el csv (y la clase) contengan más campos esto se haría más complejo, y sería muy complejo de modificar si algún día deciden introducir un campo nuevo en mitad del csv.</p>
<p>Claro este punto, debemos tener alguna forma de <strong>relacionar cada propiedad de la clase con la posicion que ocupa ese valor en el csv</strong>. Para esto tenemos dos opciones:</p>
<ul>
<li>Si la posición de cada campo es susceptible de ser modificada periódicamente deberíamos determinar esta relación en el web.config (si es una aplicación web) o en app.config (si es una aplicación de escritorio)</li>
<li>Si la posición de cada campo no es susceptible de ser modificada, es preferible agregar atributos a la clase que indique donde debemos buscar el valor de cada propiedad.</li>
</ul>
<p>Voy a centrarme en este segundo supuesto, el primero posiblemente lo trataremos en otro artículo.  Vamos a generar una clase que herede de Attribute para poder indicar en la clase que acabamos de crear donde buscaremos cada valor.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CSVFieldAttribute <span style="color: #008000;">:</span> Attribute
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">int</span> _order<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Order
    <span style="color: #000000;">&#123;</span>
        get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _order<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        set <span style="color: #000000;">&#123;</span> _order <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">public</span> CSVFieldAttribute<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> order<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        _order <span style="color: #008000;">=</span> order<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<p>Ahora modificamos la clase de la entidad, añadiéndole a cada propiedad un atributo indicando su posición en el csv. La clase quedaría como sigue:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Edades
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">int</span> _edad<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> _nombre<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> _apellido<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #000000;">&#91;</span>CSVField<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Edad
    <span style="color: #000000;">&#123;</span>
        get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _edad<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        set <span style="color: #000000;">&#123;</span> _edad <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#91;</span>CSVField<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Nombre
    <span style="color: #000000;">&#123;</span>
        get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _nombre<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        set <span style="color: #000000;">&#123;</span> _nombre <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#91;</span>CSVField<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Apellido
    <span style="color: #000000;">&#123;</span>
        get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _apellido<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        set <span style="color: #000000;">&#123;</span> _apellido <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<p>En este punto podemos elegir partir de una base en 0 o una base en 1. Yo he preferido partir de base 0 porque es la utilizada en los arrays por C#.<br />
Ya tenemos relacionada la clase de entidad con los valores del csv, ahora falta buscarnos la vida para rellenar un objeto a partir de una fila del csv. Propongo utilizar Reflexion y las Templated classes para generalizar este proceso, creando una clase que trasforme un array de valores en un objeto del tipo que le indiquemos. A las propiedades de ese objeto les asignaremos el valor (mediante reflexion) que haya en el array de valores en la posición indicada. Vayamos al tema:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CSVConverter<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> T Convert<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> values<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        Type type <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>T<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        T obj <span style="color: #008000;">=</span> Activator.<span style="color: #0000FF;">CreateInstance</span><span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">try</span>
        <span style="color: #000000;">&#123;</span>
            CSVFieldAttribute att <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
            <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> attributes <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>PropertyInfo prop <span style="color: #0600FF;">in</span> type.<span style="color: #0000FF;">GetProperties</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                attributes <span style="color: #008000;">=</span> prop.<span style="color: #0000FF;">GetCustomAttributes</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>CSVFieldAttribute<span style="color: #000000;">&#41;</span>, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>attributes.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    att <span style="color: #008000;">=</span> attributes<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #0600FF;">as</span> CSVFieldAttribute<span style="color: #008000;">;</span>
                    <span style="color: #008080; font-style: italic;">/* Si hemos optado por usar base 1 debemos poner:
                        values[att.Order - 1]
                    */</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #000000;">&#40;</span>values<span style="color: #000000;">&#91;</span>att.<span style="color: #0000FF;">Order</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Trim</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Equals</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        prop.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span>obj,
                           Convert.<span style="color: #0000FF;">ChangeType</span><span style="color: #000000;">&#40;</span>values<span style="color: #000000;">&#91;</span>att.<span style="color: #0000FF;">Order</span><span style="color: #000000;">&#93;</span>, prop.<span style="color: #0000FF;">PropertyType</span><span style="color: #000000;">&#41;</span>,
                           <span style="color: #0600FF;">null</span>
                        <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> Exception<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Error al intentar hacer la conversión de tipos.<span style="color: #008080; font-weight: bold;">\r</span><span style="color: #008080; font-weight: bold;">\n</span>&quot;</span> <span style="color: #008000;">+</span> ex.<span style="color: #0000FF;">Message</span>, ex<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">return</span> obj<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<p>Ya solo queda <strong>procesar el fichero para ir creando los objetos</strong> y hacer lo que tengamos que hacer con ellos. Para ello, nos crearemos una clase base a partir de la cual heredaremos las clases de negocio que creamos oportunas para procesar distintos modelos de csv.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ProcessCSV<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">protected</span> StreamReader _streamReader<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #FF0000;">string</span> _line<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Process<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> filename<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">try</span>
        <span style="color: #000000;">&#123;</span>
            _streamReader <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamReader<span style="color: #000000;">&#40;</span>filename<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">ProcessHeader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">ProcessBody</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">ProcessFooter</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">throw</span> ex<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">finally</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_streamReader <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                _streamReader.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> <span style="color: #0600FF;">void</span> ProcessHeader<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> Exception<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;No implementado&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> <span style="color: #0600FF;">void</span> ProcessFooter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> Exception<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;No implementado&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> <span style="color: #0600FF;">void</span> ProcessOneObject<span style="color: #000000;">&#40;</span>T obj<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> Exception<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;No implementado&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> ProcessBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        T obj <span style="color: #008000;">=</span> Activator.<span style="color: #0000FF;">CreateInstance</span><span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        _line <span style="color: #008000;">=</span> _streamReader.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>_streamReader.<span style="color: #0000FF;">EndOfStream</span> <span style="color: #008000;">&amp;&amp;</span> _line <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">&amp;&amp;</span> _line.<span style="color: #0000FF;">Trim</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> values <span style="color: #008000;">=</span> _line.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">';'</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                CSVConverter<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> converter <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CSVConverter<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                obj <span style="color: #008000;">=</span> converter.<span style="color: #0000FF;">Convert</span><span style="color: #000000;">&#40;</span>values<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">ProcessOneObject</span><span style="color: #000000;">&#40;</span>obj<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// Aquí escribiríamos algo en el log indicando qué fila ha fallado</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<p>Ya tenemos nuestra clase genérica. Pero claro, con esto no hacemos nada, si intentas parsear algo llamando a esta clase te van a saltar excepciones porque no está implementados algunos métodos necesarios. Generemos la clase que realmente usaremos.</p>
<p>Partimos de varios supuestos: el csv es el que he puesto arriba (con cabecera y pie), no vamos a usar para nada ni la cabecera ni el pie y queremos agregar a una lista para luego procesarlos (esto no lo voy a contemplar en el articulo).<br />
Al tema:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> EdadesBL <span style="color: #008000;">:</span> ProcessCSV<span style="color: #008000;">&lt;</span>Edades<span style="color: #008000;">&gt;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">private</span> List<span style="color: #008000;">&lt;</span>Edades<span style="color: #008000;">&gt;</span> _list<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">public</span> EdadesBL<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        _list <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Edades<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> ProcessHeader<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Solo leemos porque no queremos conservar la cabecera</span>
        _streamReader.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> ProcessFooter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Solo leemos porque no queremos conservar la cabecera</span>
        _streamReader.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> ProcessOneObject<span style="color: #000000;">&#40;</span>Edades obj<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Solo queremos agregarlo a la lista.</span>
        _list.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>obj<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">public</span> List<span style="color: #008000;">&lt;</span>Edades<span style="color: #008000;">&gt;</span> Edades
    <span style="color: #000000;">&#123;</span>
        get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _list<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<p>Ahora solo tenemos que <strong>procesar el fichero con dos simples líneas</strong> (en nuestro pequeño ejemplo 3 para recoger tambien la lista de Edades):</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">EdadesBL business <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> EdadesBL<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
business.<span style="color: #0000FF;">Process</span><span style="color: #000000;">&#40;</span>filename<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
List todos <span style="color: #008000;">=</span> business.<span style="color: #0000FF;">Edades</span><span style="color: #008000;">;</span></pre></div></div>

</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.oxxigeno.com/blog/2009/04/generalizando-procesamiento-csv/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Buenas prácticas: aspx sin código de servidor</title>
		<link>http://www.oxxigeno.com/blog/2009/02/buenas-practicas-aspx-sin-codigo-de-servidor/</link>
		<comments>http://www.oxxigeno.com/blog/2009/02/buenas-practicas-aspx-sin-codigo-de-servidor/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 13:45:35 +0000</pubDate>
		<dc:creator>ivinuales</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[ascx]]></category>
		<category><![CDATA[aspx]]></category>
		<category><![CDATA[microsoft]]></category>

		<guid isPermaLink="false">http://www.oxxigeno.com/blog/?p=293</guid>
		<description><![CDATA[La capa de presentación de un sitio web es una parte muy sensible del mismo, pues debe proporcionar al usuario toda la información que solicita, de forma que la carga de proceso en la misma sea mínima.
Los sitios web desarrollados bajo el .NET framework son publicados con una precompilación del código fuente, sin embargo, las [...]]]></description>
			<content:encoded><![CDATA[<p>La capa de presentación de un sitio web es una parte muy sensible del mismo, pues debe proporcionar al usuario toda la información que solicita, de forma que la carga de proceso en la misma sea mínima.</p>
<p>Los sitios web desarrollados bajo el .NET framework son publicados con una <strong>precompilación del código fuente</strong>, sin embargo, las páginas <strong>aspx</strong> y los controles <strong>ascx</strong> son interpretados en tiempo de ejecución. Es decir: cada vez que un usuario solicita una página aspx ésta es interpretada por el servidor de aplicaciones y presentada al cliente.</p>
<p>Como puede suponerse, el hecho de que la página aspx contenga código fuente que deba ser compilado ralentizará la carga de la misma, puesto que se pasa de interpretar html y devolverlo a compilar código de servidor con más o menos lógica.</p>
<p>En muchas ocasiones es posible pensar que no nos es posible <strong>crear la página aspx tal y como queremos sin incluir código de servidor</strong> en la misma, esto es un error muy común, pero facilmente subsanable, siguiendo las siguientes recomendaciones.</p>
<p><span id="more-293"></span></p>
<ul>
<li>Solo está permitido <strong>utilizar código de servidor para cargar elementos dentro de controles de tipo DataBound </strong>(GridView, FormView, etc.). Aun así es poco recomendable porque sigue requiriendo compilación. Se recomienda la utilización del <strong>control Repeater</strong>.</li>
</ul>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
                <span style="color: #ddbb00;">&amp;lt;</span>%# Eval(&quot;TipoDePagina.Nombre&quot;) %<span style="color: #ddbb00;">&amp;gt;</span>
&nbsp;
                Editar Contenidos</pre></div></div>

</blockquote>
<ul>
<li>Si necesitamos que <strong>un elemento HTML obtenga propiedades</strong> (style, href, title, etc.) desde el lado del servidor, porque utilice alguna lógica de negocio debemos identificar a éste elemento con <strong>runat=server</strong> y asignar dichas propiedades desde el <strong>code-behind</strong>, que va precompilado cuando se publica.</li>
</ul>
<p>aspx no recomendado:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;global&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;fondo-menu-&amp;lt;%= ambitoCabecera %&amp;gt;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;cabecera&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;cabecera-&amp;lt;%= ambitoCabecera%&amp;gt;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;cabecera-logo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Alt&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;imgLogo&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;../images/&amp;lt;%= image%&amp;gt;&quot;</span> <span style="color: #000066;">alt</span>=<span style="color: #ff0000;">&quot;Grupo Banco Popular&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;148&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;shortcuts&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;horizontal&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Atención al cliente<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> |<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Sucursales<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> |<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Tarifas<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> |<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Simuladores<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;buscador&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fieldset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fieldset<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</blockquote>
<p>Código no recomendado:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Imagen por omision para el logo</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> _image <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;default.jpg&quot;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">// Ambito por omision para la cabecera</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> _ambitoCabecera <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;normal&quot;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #008080;">#region Dar valores a las variables</span>
    ...
    <span style="color: #008080;">#endregion</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<p>aspx recomendado:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;global&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;cabecera&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;cabecera-logo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Alt&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> <span style="color: #000066;">alt</span>=<span style="color: #ff0000;">&quot;Grupo Banco Popular&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;148&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;shortcuts&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;horizontal&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Atención al cliente<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> |<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Sucursales<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> |<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Tarifas<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> |<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Simuladores<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;buscador&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fieldset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fieldset<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</blockquote>
<p>Código recomendado:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Imagen por omision para el logo</span>
    <span style="color: #FF0000;">string</span> image <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;default.jpg&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #008080; font-style: italic;">// Ambito por omision para la cabecera</span>
    <span style="color: #FF0000;">string</span> ambitoCabecera <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;normal&quot;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080;">#region Dar valores a las variables</span>
    ...
    <span style="color: #008080;">#endregion</span>
&nbsp;
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">global</span>.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;class&quot;</span>, <span style="color: #666666;">&quot;fondo-menu-&quot;</span> <span style="color: #008000;">+</span> ambitoCabecera<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">cabecera</span>.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;class&quot;</span>, <span style="color: #666666;">&quot;cabecera-&quot;</span> <span style="color: #008000;">+</span> ambitoCabecera<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">imgLogo</span>.<span style="color: #0000FF;">Src</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;../images/&quot;</span> <span style="color: #008000;">+</span> image<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
<ul>
<li>Si necesitamos que <strong>un elemento HTML reciba su identificador</strong>, propiedades sensibles o una maquetación compleja dependiente de una lógica de negocio, la solución optima es crear un <strong>custom web control</strong> para definirlo, éste tipo de controles heredan de la clase WebControl.</li>
</ul>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> Example.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span>.<span style="color: #0000FF;">Controls</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#91;</span>DefaultProperty<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Text&quot;</span><span style="color: #000000;">&#41;</span>, ToolboxData<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&amp;lt;{0}:OnlyText runat=server&amp;gt;&lt;!--{0}:OnlyText--&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> OnlyText <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span>.<span style="color: #0000FF;">WebControls</span></span>.<span style="color: #0000FF;">WebControl</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080;">#region Attributes</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> _text <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region Properties</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;true&quot;</span><span style="color: #000000;">&#41;</span>, Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Data&quot;</span><span style="color: #000000;">&#41;</span>, DefaultValue<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Text
        <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _text<span style="color: #008000;">;</span><span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> _text <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span><span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region Overrides Methods</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span>  Render<span style="color: #000000;">&#40;</span>HtmlTextWriter writer<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
             writer.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>Text<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.oxxigeno.com/blog/2009/02/buenas-practicas-aspx-sin-codigo-de-servidor/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Día W3C en España 2008</title>
		<link>http://www.oxxigeno.com/blog/2008/05/dia-w3c-en-espana-2008/</link>
		<comments>http://www.oxxigeno.com/blog/2008/05/dia-w3c-en-espana-2008/#comments</comments>
		<pubDate>Thu, 29 May 2008 08:57:54 +0000</pubDate>
		<dc:creator>cubeda</dc:creator>
				<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[Diseño]]></category>
		<category><![CDATA[Innovación]]></category>

		<guid isPermaLink="false">http://www.oxxigeno.com/blog/?p=3</guid>
		<description><![CDATA[
Diego Cano y yo tuvimos la oportunidad de pasarnos el pasado martes 27 por el congreso que se realizó en la UPM para celebrar el día de la W3C en España. Allí además nos juntamos con Manuel Barroso, que empezará a formar parte del equipo de Oxxigeno la próxima semana, por lo que finalmente tuvimos [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-6" title="Logo W3C" src="http://www.oxxigeno.com/blog/wp-content/uploads/2008/09/112944254_3f5212215a_o-300x166.png" alt="" width="300" height="166" /></p>
<p><a title="Ficha de Diego" href="http://www.oxxigeno.com/equipo/diego-cano-fontecha/"><strong>Diego Cano</strong></a> y <a title="Ficha de Carlos" href="http://www.oxxigeno.com/equipo/carlos-ubeda/"><strong>yo</strong></a> tuvimos la oportunidad de pasarnos el pasado martes 27 por el congreso que se realizó en la UPM para celebrar el día de la W3C en España. Allí además nos juntamos con <strong>Manuel Barroso</strong>, que empezará a formar parte del equipo de Oxxigeno la próxima semana, por lo que finalmente tuvimos una representación más que notable.</p>
<p><span id="more-3"></span></p>
<p>Bajo el lema de &#8220;Standard for Business&#8221;, el congreso se dividió en 3 grandes bloques:</p>
<ol>
<li>Accesibilidad</li>
<li>Movilidad</li>
<li>Semántica</li>
</ol>
<p>En el tiempo dedicado a <strong>Accesibilidad </strong>nos gustaron varios apuntes:</p>
<ul>
<li>¿Cómo <strong>conservar la accesibilidad </strong>en sitios dinámicos? Se propuso evolucionar del <acronym title="What You See Is What You Get">WYSIWYG</acronym> al <acronym title="What You See Is What You Mean">WYSIWYM</acronym>, dándole al usuario soluciones ya predefinidas que impiden llegar a casos de pérdida de accesibilidad. De igual modo, se defendieron flujos de trabajo que garantizaran la constancia del nivel de accesibilidad de un sitio.</li>
<li>Desde luego, se dejó suficientemente claro que las necesidades de accesibilidad no son algo exclusivo de usuarios con discapacidades, sino que estas necesidades son algo fundamental para una experiencia de usuario mínima desde <strong>dispositivos móviles</strong>.</li>
</ul>
<p>Ese punto conectó con la parte de <strong>Movilidad</strong>:</p>
<ul>
<li>El mayor debate se centró entre la decisión de &#8220;adaptar&#8221; un sitio web a un dispositivo o apostar por una web única con cierta capacidad de &#8220;transformación dinámica&#8221;.</li>
<li>A pesar de la apuesta de la W3C por &#8220;una web, distintos dispositivos&#8221; se pudieron ver buenos ejemplos de <strong>adaptación al dispositivo móvil</strong>, como <a href="http://www.soitu.es/">soitu</a>. También, por otro lado, se presentaron <strong>transformaciones automáticas</strong> interesantes mediante <a href="http://merkur.fundacionctic.org/">Merkur</a> y <a href="http://mymobileweb.morfeo-project.org/">MyMobileWeb</a>.</li>
<li>En otro terreno un poco diferente, también nos gustó la presentación del &#8220;Push Gateway&#8221; de Vodafone R&amp;D: Un interesante sistema para acceder a la <strong>información del móvil a partir de un ordenador</strong> u otro dispositivo que resultó todavía más apasionante con la posibilidad de usar el móvil como un emisor conectado a cualquier tipo de sensor.</li>
</ul>
<p>Ya en el área de <strong>Semántica </strong>pudimos centrarnos en otros puntos:</p>
<ul>
<li>Se mostraron <strong>casos de éxito</strong> de aplicaciones semánticas, tanto culturales, como en banca o industria.</li>
<li>Se presentaron, sin embargo, diversos <strong>problemas de interoperabilidad</strong> entre diferentes sintaxis. Esto motivó un más o menos acalorado debate entre los defensores de la agilidad y descentralización de los <strong>Microformatos </strong>y los que los consideran una buena ayuda a una web semántica por llegar, pero nada más.</li>
</ul>
<p>Desde nuestro punto de vista, fue una jornada interesante, donde</p>
<ul>
<li>Se habló de accesibilidad con bastante sentido común y una visión integradora</li>
<li>Se aclararon algunos temas de movilidad y se presentaron propuestas novedosas</li>
<li>Se participó en un intenso debate sobre web semántica</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.oxxigeno.com/blog/2008/05/dia-w3c-en-espana-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.411 seconds -->
