<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.southworks.net/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Leandro Boffi</title>
	
	<link>http://blogs.southworks.net/lboffi</link>
	<description>Microsoft .NET Evangelism Experiences</description>
	<pubDate>Wed, 19 Nov 2008 13:56:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.southworks.net/lboffi" /><feedburner:info uri="lboffi" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:browserFriendly></feedburner:browserFriendly><item>
		<title>Microsoft Azure Services Management Tools</title>
		<link>http://blogs.southworks.net/lboffi/2008/11/02/microsoft-azure-services-management-tools/</link>
		<comments>http://blogs.southworks.net/lboffi/2008/11/02/microsoft-azure-services-management-tools/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 22:07:12 +0000</pubDate>
		<dc:creator />
		
		<category><![CDATA[PDC]]></category>

		<category><![CDATA[PowerShell]]></category>

		<category><![CDATA[Windows Azure]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/lboffi/2008/11/02/microsoft-azure-services-management-tools/</guid>
		<description><![CDATA[A few months ago I&#8217;ve been working with my colleagues Mr. Angel &#34;Java&#34; Lopez, and Mr. Pablo &#34;Lito&#34; Damiani in the Azure Services Management Tools. I&#8217;m really proud to say I&#8217;ve been part of this project. We also has been supported by other Southies like Maximiliano Deboli , Sebastian Iacomuzzi, Edgardo Rossetto, Pablo Costantini, Matias [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago I&#8217;ve been working with my colleagues Mr. <a href="http://www.ajlopez.com/">Angel &quot;Java&quot; Lopez</a>, and Mr. <a href="http://blogs.southworks.net/pdamiani">Pablo &quot;Lito&quot; Damiani</a> in the <a href="http://code.msdn.microsoft.com/AzureManagementTools">Azure Services Management Tools</a>. I&#8217;m really proud to say I&#8217;ve been part of this project. We also has been supported by other Southies like <a href="http://blogs.southworks.net/mdeboli/" target="_blank">Maximiliano Deboli</a> , <a href="http://blogs.southworks.net/siacomuzzi/" target="_blank">Sebastian Iacomuzzi</a>, <a href="http://blogs.southworks.net/erossetto" target="_blank">Edgardo Rossetto</a>, <a href="http://blogs.southworks.net/pcostantini/" target="_blank">Pablo Costantini</a>, <a href="http://blogs.southworks.net/mwoloski" target="_blank">Matias Woloski</a> and <a href="http://blogs.southworks.net/parancibia/" target="_blank">Paulo Arancibia</a> (our UX great master).</p>
<p>During this project we created a set of tool for enable easy management of the new Microsoft&#8217;s Azure Services. Windows Azure Services Platform has been just announced at <a href="http://www.microsoftpdc.com/">Microsoft PDC</a> as the Microsoft&#8217;s processing platform on the clouds. Now cloud computing takes the center stage. </p>
<p><a href="http://www.microsoft.com/azure" target="_blank"><img height="406" alt="azure" src="http://blogs.southworks.net/lboffi/files/2008/11/windowslivewriterwindowsazureservicesmanagementtools-f0d2azure.png" width="644" border="0" /></a></p>
<p>We could quickly say that Azure is an <a href="http://en.wikipedia.org/wiki/Software_as_a_Service">Software as a Service</a> Platform, that runs on Microsoft Infrastructure. </p>
<p>The Azure Services Management tools that we created allow to manage <a href="http://www.microsoft.com/azure/sql.mspx">SQL Data Services</a>, an storage on the clouds, and <a href="http://www.microsoft.com/azure/netservices.mspx">.NET Services</a> including, <a href="http://www.microsoft.com/azure/accesscontrol.mspx">Access Control</a> and <a href="http://www.microsoft.com/azure/workflow.mspx">Workflow Services</a>.</p>
<p><img height="244" alt="azureArchitecture" src="http://blogs.southworks.net/lboffi/files/2008/11/windowslivewriterwindowsazureservicesmanagementtools-f0d2azurearchitecture.png" width="506" border="0" /> </p>
<p>This tools include a set of Powershell Commandlets to work with Access Control, Workflow Services and SQL Data Services. We also include an unified Windows Management Console Snap-In as UI to work with this commandlets.</p>
<p><img height="318" alt="2008-10-27-ManagementTools" src="http://blogs.southworks.net/lboffi/files/2008/11/windowslivewriterwindowsazureservicesmanagementtools-f0d22008-10-27-managementtools-35fd6fea-2757-4d48-8e6b-0a7c78c8a0ec.png" width="483" border="0" /> </p>
<p>This tools has been used at PDC presentation: <a href="http://channel9.msdn.com/pdc2008/BB11/" target="_blank">Identity Roadmap for Software + Services</a>.</p>
<h3>Resources</h3>
<ul>
<li><font size="2">Azure Services Management Tools + Source Code: </font><a title="http://code.msdn.microsoft.com/AzureManagementTools" href="http://code.msdn.microsoft.com/AzureManagementTools"><font size="2">http://code.msdn.microsoft.com/AzureManagementTools</font></a> </li>
<li>Windows Azure: <a href="http://www.microsoft.com/azure">http://www.microsoft.com/azure</a> </li>
<li>Windows Azure Developer Center: <a title="http://msdn.microsoft.com/en-us/azure/default.aspx" href="http://msdn.microsoft.com/en-us/azure/default.aspx">http://msdn.microsoft.com/en-us/azure/default.aspx</a>&#160; </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blogs.southworks.net/lboffi/2008/11/02/microsoft-azure-services-management-tools/feed/</wfw:commentRss>
		</item>
		<item>
		<title>WCF AJAX-Friendly Services</title>
		<link>http://blogs.southworks.net/lboffi/2008/10/30/wcf-ajax-friendly-services/</link>
		<comments>http://blogs.southworks.net/lboffi/2008/10/30/wcf-ajax-friendly-services/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 00:46:18 +0000</pubDate>
		<dc:creator />
		
		<category><![CDATA[AJAX]]></category>

		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/lboffi/?p=39</guid>
		<description><![CDATA[At one of my first jobs as web developer I worked with a friend, Gustavo Miranda, A.K.A Morph, we used PHP language. We maintained three websites at different datacenters, but the owner was the same (my friend&#8217;s uncle). At that time, one day, we had an integration request: one of the websites should show data [...]]]></description>
			<content:encoded><![CDATA[<p>At one of my first jobs as web developer I worked with a friend, Gustavo Miranda, A.K.A Morph, we used PHP language. We maintained three websites at different datacenters, but the owner was the same (my friend&#8217;s uncle). At that time, one day, we had an integration request: one of the websites should show data stored at the others.</p>
<p>Right now it&#8217;s clear that the use web services is the best solution, but at that time, we were about seventeen years old and we had no idea about ajax or web services because they were not so popular.</p>
<p>So we started to think and research, and finally we found a solution: We had a PHP page that could return plain text, and to call it, we used a hidden IFRAME, and we use java script to read, parse and show the information.</p>
<p>Sometime later I learned about XML, so I started to create POX (Plain Old XML) &#8220;Services&#8221; (but I didn&#8217;t use to call them &#8220;POX services&#8221; ), and use the XmlHttpRequest object to make requests. After that, SOAP came, and, in my opinion, mistakenly called &#8220;Web&#8221; Services became popular.</p>
<p>Today, AJAX and Services are in their plenitude, Microsoft has his own AJAX framework, and the creation of services has never been so easy like using WCF.</p>
<p>In this post, I would like to show how easy it is to create &amp; consume AJAX-friendly services combining the new WCF 3.5 service behaviors &amp; bindings and the Microsoft AJAX framework. </p>
<h3>Creating the Service</h3>
<p>As creating any service, we should start by the contract. In this case, I will use a Meetings Request service. So these will be my <b>DataContracts</b>:</p>
<table cellspacing="4" cellpadding="2" width="400" border="0">
<tbody>
<tr>
<td valign="top" width="200"><img height="309" alt="meetingRquestContract" src="http://blogs.southworks.net/lboffi/files/2008/10/windowslivewriterwcfajaxfriendlyservices-13c43meetingrquestcontract-1.jpg" width="318" border="0" /> </td>
<td valign="top" width="200"><img height="394" alt="personContract" src="http://blogs.southworks.net/lboffi/files/2008/10/windowslivewriterwcfajaxfriendlyservices-13c43personcontract.jpg" width="385" border="0" /> </td>
</tr>
</tbody>
</table>
<p>And this will be my <b>ServiceContract</b>:</p>
<p><img height="263" alt="serviceContract" src="http://blogs.southworks.net/lboffi/files/2008/10/windowslivewriterwcfajaxfriendlyservices-13c43servicecontract.jpg" width="450" border="0" /> </p>
<p>As you can see I&#8217;m providing a <b>Namespace </b>to the <b>ServiceContract</b> attribute, this is important because this namespace will be the one that we will use from javascript. We will focus in the <b>GetMeetingPage </b>method, for demo proposes we will have only one <b>MeetingRequest </b>by page.</p>
<p>Once we have our contracts, let&#8217;s create the service; to do this, we will use the <b>AJAX-enabled WCF Service </b>Template:</p>
<p><img height="316" alt="template" src="http://blogs.southworks.net/lboffi/files/2008/10/windowslivewriterwcfajaxfriendlyservices-13c43template.jpg" width="428" border="0" />&#160;</p>
<p>This will create a <b>Meetings.svc </b>file<b> </b>and its code behind <b>Meetings.svc.cs</b>, it will also create a section in the <b>Web.config </b>file to configure the service, so let&#8217;s go step by step. </p>
<p><b>MeetingsService.svc: </b>The <b>ServiceHost</b> file. The important thing here is the <b>Service</b> property; this property specifies the <b>type</b> that will contain our service functionality.</p>
<p>&#160;<img height="100" alt="serviceHost" src="http://blogs.southworks.net/lboffi/files/2008/10/windowslivewriterwcfajaxfriendlyservices-13c43servicehost-1.jpg" width="602" border="0" /> </p>
<p>The first thing to do inside it is to clean up the service class, located at the code behind, and implement our <b>ServiceContract, IMeetingsService</b>, the result should be the next one:</p>
<p>&#160;<img height="349" alt="meetingsService" src="http://blogs.southworks.net/lboffi/files/2008/10/windowslivewriterwcfajaxfriendlyservices-13c43meetingsservice.jpg" width="445" border="0" /> </p>
<p>Note that the <b>MeetingsService </b>class implements our <b>ServiceContract, IMeetingsService. </b>To keep it simple, I&#8217;m using a static class named <b>MeetingsStore</b> to encapsulate the data access logic, just to get notice I&#8217;m using mockdata and <b>LinqToObjects</b> to retrieve it.</p>
<p>The next step is to configure our service. The goal of WCF is that we can configure our service through metadata. </p>
<p>To create SOAP services that work through HTTP, we commonly use bindings like <b>basicHttpBinding</b> or <b>wsHttpBinding</b>. But, as you know, negotiating with SOAP messages from javascript is pretty complex, so we need a binding that allow our enpoinds respond to HTTP requests instead of SOAP messages: the solution is the new <b>webHttpBinding</b>, available from WCF 3.5.</p>
<p><img height="354" alt="webConfig" src="http://blogs.southworks.net/lboffi/files/2008/10/windowslivewriterwcfajaxfriendlyservices-13c43webconfig-e21ad715-64f6-419b-9366-adff309259f9.jpg" width="676" border="0" /></p>
<p>As you can see in this <b>Web.config</b> screenshot, we set our binding as <b>webHttpBinding, </b>our contract and our behavior. Let&#8217;s stop a second in the behavior, as you can see we are using the <b>enableWebScript</b> behavior, this behavior is the one that makes the magic to allow us to consume our service from ASP.NET AJAX web pages, later we will see this in detail.</p>
<p>So, that&#8217;s all for our service, let&#8217;s consume it&#8230;</p>
<h3>Consuming the service</h3>
<p>To consume the service the first thing to do is create an AJAX-enabled aspx page, by using the &#8220;AJAX Web Form&#8221; template or just adding a <b>ScriptManager</b> component to any aspx page. If you use Master Pages, the <b>ScriptManager </b>component should be placed in the master page, and the content pages should use the <b>ScriptManagerProxy </b>component.</p>
<p>The first thing to do is to give to the <b>ScriptManager</b> a reference to our service, that&#8217;s what you can see in this screenshot:</p>
<p><img height="84" alt="jsservicereference" src="http://blogs.southworks.net/lboffi/files/2008/10/windowslivewriterwcfajaxfriendlyservices-13c43jsservicereference.jpg" width="414" border="0" />&#160;</p>
<p>If we run this page, it looks like nothing is happening, but if we research in the generated html code; we will find something like this:</p>
<p><img height="44" alt="source" src="http://blogs.southworks.net/lboffi/files/2008/10/windowslivewriterwcfajaxfriendlyservices-13c43source.jpg" width="531" border="0" /> </p>
<p>What?? It looks like we are adding a javascript file reference, but instead of <b>myLocalJsFile.js</b> we have <b>MeetingsService.svc/jsdebug</b>. Do you remember the <b>enableWebScript </b>behavior? This is exactly it. If we copy &amp; paste this reference in our browser, something will happen&#8230;</p>
<p><img height="387" alt="downladingthemagic" src="http://blogs.southworks.net/lboffi/files/2008/10/windowslivewriterwcfajaxfriendlyservices-13c43downladingthemagic.jpg" width="509" border="0" /> </p>
<p>We used <b>enableWebScript </b>behavior in our service, this means that if we append <b>/jsdebug </b>or just <b>/js </b>to our service URI, it will return a file containing a javascript proxy to our service. If we save and open this file with Visual Studio we will see what it means:</p>
<p><img height="595" alt="jsproxy" src="http://blogs.southworks.net/lboffi/files/2008/10/windowslivewriterwcfajaxfriendlyservices-13c43jsproxy.jpg" width="637" border="0" /></p>
<p>As you can see, this file contains a JSON definition having the same methods that our service contract <b>IMeetingsService</b>, and in the first line we have a namespace registration, the same namespace that we defined in our <b>ServiceContract. </b>So, let&#8217;s back to our .aspx page and invoke the service.</p>
<p>To do this, we just have to create an instance of this proxy, in this case <b>ajaxfriendly.services.IMeetingsService</b>, and use its methods, and this task is especially easy using Visual Studio 2008, because we have javascript intellisense &amp; debugging&#8230;</p>
<p><img height="163" alt="jsintellisense" src="http://blogs.southworks.net/lboffi/files/2008/10/windowslivewriterwcfajaxfriendlyservices-13c43jsintellisense.jpg" width="439" border="0" /> </p>
<p>To call any method we have to provide the service parameters and also, because this will run asynchronous, we have to provide one handler to succeededCallback event, and another to failedCallbackEvent. Finally we will have something like this&#8230;</p>
<p><img height="286" alt="js" src="http://blogs.southworks.net/lboffi/files/2008/10/windowslivewriterwcfajaxfriendlyservices-13c43js-347c14ba-8311-4431-9fa7-5f25a2ab276d.png" width="659" border="0" /> </p>
<p>In the succeededCallback event handler we just display the data. If we run and debug, we can see that in the &#8220;result&#8221; parameter we&#8217;ve our <b>DataContract</b> retrieved by our service in JSON.</p>
<p>An that&#8217;s all, the next is play with JavaScript, JQuery (recommended), to manage this data.</p>
<p>You can download the <a href="http://nxvkya.blu.livefilestore.com/y1p3lkKQwDViHZOF4GMMP77encKqzfHC0GVIPj1nd2c9gyTuNNJrjK6xz0sWrmHqa-T7fu5oKrx_L4/Blog.Samples.WCF.AjaxFriendlyService.zip?download">Code Here</a>.</p>
<p>Regards!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.southworks.net/lboffi/2008/10/30/wcf-ajax-friendly-services/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ASP.NET MVC "Grid View" made in Home</title>
		<link>http://blogs.southworks.net/lboffi/2008/10/01/aspnet-mvc-grid-view-made-in-home/</link>
		<comments>http://blogs.southworks.net/lboffi/2008/10/01/aspnet-mvc-grid-view-made-in-home/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 03:52:46 +0000</pubDate>
		<dc:creator />
		
		<category><![CDATA[ASP.NET MVC]]></category>

		<category><![CDATA[Patterns]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/lboffi/?p=38</guid>
		<description><![CDATA[The first time that I saw ASP.NET MVC, I was at a Microsoft Tech-night, the speaker was my admired co-worker, Edgardo Rossetto, and I felt in love with the framework. It brought me many memories about my ASP 3.0 developer time.
ASP.NET MVC is not a replace for ASP.NET Web Forms model, is just another choice, [...]]]></description>
			<content:encoded><![CDATA[<p>The first time that I saw ASP.NET MVC, I was at a Microsoft Tech-night, the speaker was my admired co-worker, Edgardo Rossetto, and I felt in love with the framework. It brought me many memories about my ASP 3.0 developer time.</p>
<p>ASP.NET MVC is not a replace for ASP.NET Web Forms model, is just another choice, and I really like, because I&#8217;m a patterns lover and, as you can imagine, ASP.NET MVC is based on the famous <a href="http://en.wikipedia.org/wiki/Model-view-controller">MVC Pattern</a>, but also is great because enable easy <a href="http://en.wikipedia.org/wiki/Test-driven_development">Test-Driven Development</a>, and every single action is easy mapped to a <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a>-friendly URL.</p>
<p>So, given that, I want to share with you a little home-made project, my own ASP.NET MVC Grid View.</p>
<p>Before you feel so excited, it do not support paging and sorting (yet), but you can easily add these features in your controller. Right now, it supports simply &quot;Data Source&quot; (any IEnumarable object), extensible &quot;Column Definitions&quot; and CSS Styles.</p>
<p>&#160;</p>
<h2>How to use it?</h2>
<p>This grid View is basically composed by a Web Control, and a set of &quot;model&quot; classes.</p>
<p><img border="0" alt="mvcgrid" src="http://blogs.southworks.net/lboffi/files/2008/10/mvcgrid.jpg" width="233" height="171" />&#160;</p>
<p>The data (DataSource, ColumnDefinitions, CSS Styles, etc&#8230;) is given to the WebControl as ViewData. Let&#8217;s see that&#8230;</p>
<p><b>Mock Data (Just a method that returns a list of users):</b></p>
<p><img border="0" alt="mvcgrid4" src="http://blogs.southworks.net/lboffi/files/2008/10/mvcgrid4.jpg" width="582" height="454" />&#160;</p>
<p><b>Controller example code (DataSource &amp; Column Definitions at Controller):</b></p>
<p><img border="0" alt="mvcgrid1" src="http://blogs.southworks.net/lboffi/files/2008/10/mvcgrid1.jpg" width="410" height="419" /> </p>
<p><strong></strong></p>
<p><strong>View example code:</strong></p>
<p><img border="0" alt="mvcgrid2" src="http://blogs.southworks.net/lboffi/files/2008/10/mvcgrid2.jpg" width="601" height="57" /> </p>
<p><strong>The result:</strong></p>
<p><img border="0" alt="mvcgrid3" src="http://blogs.southworks.net/lboffi/files/2008/10/mvcgrid3.jpg" width="421" height="148" /> </p>
<h2>How does it work?</h2>
<p>The method in change of render the value of each field is place in <b>GridColumnDefinition </b>base class. As you can imagine, it&#8217;s based on reflection, using the value of <b>PropertyName </b>to find the value to render. </p>
<p>This is the magic method:</p>
<p><img border="0" alt="mvcgrid5" src="http://blogs.southworks.net/lboffi/files/2008/10/mvcgrid5.jpg" width="698" height="420" /> </p>
<p>Here we&#8217;ve something cool; this method is also based on <a href="http://en.wikipedia.org/wiki/Template_method_pattern">Template Method Pattern</a>, to allow formatting the value before render, so you can write your own implementation of the <b>FormatValue</b> method.</p>
<p>I&#8217;ve written three as example&#8230;</p>
<p>&#160;</p>
<p><img border="0" alt="image" src="http://blogs.southworks.net/lboffi/files/2008/10/image.png" width="524" height="499" /> </p>
<p>This is the <strong>GridImageColumn</strong> implementation of <strong>FormatValue, </strong>to render an HTML image with the value&#8230;</p>
<p><img border="0" alt="mvcgrid7" src="http://blogs.southworks.net/lboffi/files/2008/10/mvcgrid7.jpg" width="562" height="147" /> </p>
<p>Perhaps an &quot;Action&quot; column definition can be implemented giving as value the Id; it&#8217;s free to your imagination!</p>
<p>You can download the source code <a href="http://nxvkya.blu.livefilestore.com/y1pBUzmIwPgA_miml1889a5IwL4xCTzSS3y_B-ev5L7YG6P6mr7LFJB0vkgFXsm6K7I9GdJ0NqwwnU/MvcGridView.zip?download">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.southworks.net/lboffi/2008/10/01/aspnet-mvc-grid-view-made-in-home/feed/</wfw:commentRss>
		</item>
		<item>
		<title>CodeCamp 2008 - This time at home</title>
		<link>http://blogs.southworks.net/lboffi/2008/09/30/codecamp-2008-this-time-at-home/</link>
		<comments>http://blogs.southworks.net/lboffi/2008/09/30/codecamp-2008-this-time-at-home/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 23:40:37 +0000</pubDate>
		<dc:creator />
		
		<category><![CDATA[CodeCamp]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/lboffi/2008/09/30/codecamp-2008-this-time-at-home/</guid>
		<description><![CDATA[The next Saturday 4th-Oct, the Microsoft CodeCamp will take place, once again. 
This time is really special for me mainly because of two reasons.
The first one is that, this year, the event will be located at the UAI. This university is a place I&#8217;m really fond of, because it&#8217;s where I had one of my [...]]]></description>
			<content:encoded><![CDATA[<p>The next Saturday 4th-Oct, the Microsoft CodeCamp will take place, once again. </p>
<p>This time is really special for me mainly because of two reasons.</p>
<p>The first one is that, this year, the event will be located at the <a href="http://www.uai.edu.ar">UAI</a>. This university is a place I&#8217;m really fond of, because it&#8217;s where I had one of my first work opportunities in the software industry.</p>
<p>A couple years ago I worked at the Center of High Studies in Information Technology (<a href="http://www.caeti.uai.edu.ar">CAETI</a>) of this University, where I was able to increase my passion for technology in the fields of research and development, working on topics such as robotics, electronics, and software development, but basically learning a lot and meeting people ready to teach and learn.</p>
<p>On the other hand, as you can see in the post made by <a href="http://blogs.southworks.net/aortega/2008/09/28/codecamp-2008-this-time-iis7-4x4-and-application-monitoring-with-ops-mgr/">Mr. Alberto Ortega,</a> a handful of my admired work mates at Southworks (another place where I can keep up with my passion for technologies) will be in charge of some presentations, so I&#8217;ll be there, as an spectator, to support them.</p>
<p>If you didn&#8217;t register yet, don&#8217;t miss the chance, I promise you won&#8217;t be disappointed: <a href="http://www.microsoft.com/Argentina/CodeCamp/">http://www.microsoft.com/Argentina/CodeCamp/</a></p>
<p>Hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.southworks.net/lboffi/2008/09/30/codecamp-2008-this-time-at-home/feed/</wfw:commentRss>
		</item>
		<item>
		<title>WCF DataContract Serializer</title>
		<link>http://blogs.southworks.net/lboffi/2008/07/16/wcf-datacontract-serializer/</link>
		<comments>http://blogs.southworks.net/lboffi/2008/07/16/wcf-datacontract-serializer/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 17:21:23 +0000</pubDate>
		<dc:creator />
		
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/lboffi/2008/07/17/wcf-datacontract-serializer/</guid>
		<description><![CDATA[I want to share with you something I found very useful. In this post I&#8217;ll show how to use the WCF Serializer to serialize and deserialize objects into XML files. I&#8217;ve learn that from my coworker Edgardo Rossetto.
I&#8217;ve wrote in the previous post about WCF, to send an receive messages WCF needs to serialize and [...]]]></description>
			<content:encoded><![CDATA[<p>I want to share with you something I found very useful. In this post I&#8217;ll show how to use the WCF Serializer to serialize and deserialize objects into XML files. I&#8217;ve learn that from my coworker <a href="http://blogs.southworks.net/erossetto">Edgardo Rossetto</a>.</p>
<p>I&#8217;ve wrote in the previous post about WCF, to send an receive messages WCF needs to serialize and deserialize objects, to do this in the assembly <strong>System.Runtime.Serialization</strong> there is a class called <strong>DataContractSerializer</strong></p>
<blockquote><p><span style="font-size: x-small;font-family: consolas"><strong>public sealed class </strong>DataContractSerializer : System.Runtime.Serialization.XmlObjectSerializer        <br />&#160;&#160;&#160; Member of System.Runtime.Serialization </span></p>
<p><span style="font-size: x-small;font-family: consolas"><strong>Summary:</strong>        <br />Serializes and deserializes an instance of a type into an XML stream or document using a supplied data contract. This class cannot be inherited.</span></p>
</blockquote>
<p>So, let&#8217;s see an example&#8230;</p>
<p>The first step is tag our model classes with <strong>DataContract </strong>and <strong>DataMember </strong>attributes.</p>
<table cellspacing="2" cellpadding="0" width="100%" bgcolor="#3f3f3f" border="0">
<tbody>
<tr>
<td valign="top" width="400">
<pre><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #eaeaac"><strong>using </strong></span><span style="color: #dfdfbf">System</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Collections</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">ObjectModel</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">;
</span><span style="color: #eaeaac"><strong>using </strong></span><span style="color: #dfdfbf">System</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Runtime</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Serialization</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">;

</span><span style="color: #dcdccc">[</span><span style="color: #f0dfaf">DataContract</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">]
</span><span style="color: #eaeaac">public class </span></font></span></span><span style="color: #f0dfaf"><span style="font-size: x-small;font-family: consolas"><font size="2">Person
</font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">{
    </span><span style="color: #eaeaac">private </span><span style="color: #f0dfaf">Collection</span><span style="color: #dcdccc">&lt;</span><span style="color: #f0dfaf">Address</span><span style="color: #dcdccc">&gt; </span><span style="color: #dfdfbf">address</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">;

    [</span><span style="color: #f0dfaf">DataMember</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">]
    </span><span style="color: #eaeaac">public int </span><span style="color: #dfdfbf">Id </span><span style="color: #dcdccc">{ </span><span style="color: #eaeaac">get</span><span style="color: #dcdccc">; </span><span style="color: #eaeaac">set</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">; }

    [</span><span style="color: #f0dfaf">DataMember</span><span style="color: #dcdccc">(</span><span style="color: #dfdfbf">IsRequired</span><span style="color: #dcdccc">=</span><span style="color: #eaeaac">false</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">)]
    </span><span style="color: #eaeaac">public string </span><span style="color: #dfdfbf">Name </span><span style="color: #dcdccc">{ </span><span style="color: #eaeaac">get</span><span style="color: #dcdccc">; </span><span style="color: #eaeaac">set</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">; }

    [</span><span style="color: #f0dfaf">DataMember</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">]
    </span><span style="color: #eaeaac">public </span><span style="color: #f0dfaf">Collection</span><span style="color: #dcdccc">&lt;</span><span style="color: #f0dfaf">Address</span><span style="color: #dcdccc">&gt; </span></font></span></span><span style="color: #dfdfbf"><span style="font-size: x-small;font-family: consolas"><font size="2">Address
    </font></span></span><span style="color: #dcdccc"><span style="font-size: x-small;font-family: consolas"><font size="2">{
        </font></span></span><span style="color: #eaeaac"><span style="font-size: x-small;font-family: consolas"><font size="2">get
        </font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">{
            </span><span style="color: #eaeaac">if </span><span style="color: #dcdccc">(</span><span style="color: #eaeaac">this</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">address </span><span style="color: #dcdccc">== </span><span style="color: #eaeaac">null</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">)
            {
                </span><span style="color: #eaeaac">this</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">address </span><span style="color: #dcdccc">= </span><span style="color: #eaeaac">new </span><span style="color: #f0dfaf">Collection</span><span style="color: #dcdccc">&lt;</span><span style="color: #f0dfaf">Address</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">&gt;();
            }

            </span><span style="color: #eaeaac">return this</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">address</span></font></span></span><span style="color: #dcdccc"><span style="font-size: x-small;font-family: consolas"><font size="2">;
        }
        </font></span></span><span style="color: #eaeaac"><span style="font-size: x-small;font-family: consolas"><font size="2">set
        </font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">{
            </span><span style="color: #eaeaac">this</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">address </span><span style="color: #dcdccc">= </span><span style="color: #eaeaac">value</span></font></span></span><span style="color: #dcdccc"><span style="font-size: x-small;font-family: consolas"><font size="2">;
        }
    }
}</font></span></span></pre>
<p>
          <br /><a href="http://11011.net/software/vspaste"><font face="Consolas" size="2"></font></a></p>
<p></p>
<pre><font size="2"><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #dcdccc">[</span><span style="color: #f0dfaf">DataContract</span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #dcdccc">]</span></span></span></font><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #dcdccc">
</span><span style="color: #eaeaac"><strong><font size="2">public class </font></strong></span></span></span><span style="color: #f0dfaf"><span style="font-size: x-small;font-family: consolas"><font size="2">Address
</font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #dcdccc"><font size="2">{
</font></span></span></span></pre>
<p><font size="2"><br />
            <br /><font face="Consolas"></font></font></p>
<pre><font size="2"><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #dcdccc">    [</span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #f0dfaf">DataMember</span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #dcdccc">]</span></span></span></font><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #dcdccc">
<font size="2">    </font></span><font size="2"><span style="color: #eaeaac"><strong>public string </strong></span><span style="color: #dfdfbf">Street </span><span style="color: #dcdccc">{ </span><span style="color: #eaeaac">get</span><span style="color: #dcdccc">; </span><span style="color: #eaeaac">set</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #dcdccc"><font size="2">; }

</font></span></span></span></pre>
<p><font size="2"><br />
            <br /><font face="Consolas"></font></font></p>
<pre><font size="2"><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #dcdccc">    [</span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #f0dfaf">DataMember</span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #dcdccc">]</span></span></span></font><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #dcdccc">
<font size="2">    </font></span><font size="2"><span style="color: #eaeaac"><strong>public int </strong></span><span style="color: #dfdfbf">Number </span><span style="color: #dcdccc">{ </span><span style="color: #eaeaac">get</span><span style="color: #dcdccc">; </span><span style="color: #eaeaac">set</span></font></span></span><span style="color: #dcdccc"><span style="font-size: x-small;font-family: consolas"><font size="2">; }
}</font></span></span></pre>
</td>
</tr>
</tbody>
</table>
<p>Notice, we want to serialize and deserialize the Person class, but it has a one-to-many relationship with Address class, so both classes should be tagged as <strong>DataContracts </strong>and the members we want to serialize should be tagged with <strong>DataMember </strong>attribute, a little detail to denote is that the property Name of Person class is defined as not required, this means that we don&#8217;t need to have a value for this property.</p>
<p>After we have all our classes tagged we need to create a helper class to work with <strong>DataContractSerializer</strong>. Usually this class is defined with generic methods, because in that way we can use the same class to serialize and deserialize any kind of objects.</p>
<table cellspacing="2" cellpadding="0" width="100%" bgcolor="#3f3f3f" border="0">
<tbody>
<tr>
<td>
<pre><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #eaeaac">using </span><span style="color: #dfdfbf">System</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">;
</span><span style="color: #eaeaac">using </span><span style="color: #dfdfbf">System</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Runtime</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Serialization</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">;
</span><span style="color: #eaeaac">using </span><span style="color: #dfdfbf">System</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Xml</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">;

</span><span style="color: #eaeaac">public class </span></font></span></span><span style="color: #f0dfaf"><span style="font-size: x-small;font-family: consolas"><font size="2">ModelSerializer
</font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">{
    </span><span style="color: #eaeaac">public virtual </span><span style="color: #dfdfbf">TModel Deserialize</span><span style="color: #dcdccc">&lt;</span><span style="color: #dfdfbf">TModel</span><span style="color: #dcdccc">&gt;(</span><span style="color: #eaeaac">string </span><span style="color: #dfdfbf">path</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">)
    {
        </span><span style="color: #f0dfaf">XmlReader </span><span style="color: #dfdfbf">reader </span><span style="color: #dcdccc">= </span><span style="color: #f0dfaf">XmlReader</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Create</span><span style="color: #dcdccc">(</span><span style="color: #dfdfbf">path</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">);

        </span><span style="color: #f0dfaf">DataContractSerializer </span><span style="color: #dfdfbf">serializer </span><span style="color: #dcdccc">= </span><span style="color: #eaeaac">new </span><span style="color: #f0dfaf">DataContractSerializer</span><span style="color: #dcdccc">(</span><span style="color: #eaeaac">typeof</span><span style="color: #dcdccc">(</span><span style="color: #dfdfbf">TModel</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">));
        </span><span style="color: #dfdfbf">TModel result </span><span style="color: #dcdccc">= (</span><span style="color: #dfdfbf">TModel</span><span style="color: #dcdccc">)</span><span style="color: #dfdfbf">serializer</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">ReadObject</span><span style="color: #dcdccc">(</span><span style="color: #dfdfbf">reader</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">);

        </span><span style="color: #eaeaac">return </span><span style="color: #dfdfbf">result</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">;
    }

    </span><span style="color: #eaeaac">public virtual void </span><span style="color: #dfdfbf">Serialize</span><span style="color: #dcdccc">&lt;</span><span style="color: #dfdfbf">TModel</span><span style="color: #dcdccc">&gt;(</span><span style="color: #dfdfbf">TModel model</span><span style="color: #dcdccc">, </span><span style="color: #eaeaac">string </span><span style="color: #dfdfbf">path</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">)
    {
        </span><span style="color: #f0dfaf">XmlWriter </span><span style="color: #dfdfbf">writer </span><span style="color: #dcdccc">= </span><span style="color: #f0dfaf">XmlWriter</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Create</span><span style="color: #dcdccc">(</span><span style="color: #dfdfbf">path</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">);

        </span><span style="color: #f0dfaf">DataContractSerializer </span><span style="color: #dfdfbf">serializer </span><span style="color: #dcdccc">= </span><span style="color: #eaeaac">new </span><span style="color: #f0dfaf">DataContractSerializer</span><span style="color: #dcdccc">(</span><span style="color: #eaeaac">typeof</span><span style="color: #dcdccc">(</span><span style="color: #dfdfbf">TModel</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">));
        </span><span style="color: #dfdfbf">serializer</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">WriteObject</span><span style="color: #dcdccc">(</span><span style="color: #dfdfbf">writer</span><span style="color: #dcdccc">, </span><span style="color: #dfdfbf">model</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">);

        </span><span style="color: #dfdfbf">writer</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Flush</span></font></span></span><span style="color: #dcdccc"><span style="font-size: x-small;font-family: consolas"><font size="2">();
    }
}</font></span></span></pre>
</td>
</tr>
</tbody>
</table>
<p>This class has two generic methods, Serialize and Deserialize, as you can see both methods uses the <strong>DataContractSerializer</strong> giving as parameter the generic type TModel.</p>
<p>The implementation is very simple, you only need an <strong>XmlReader</strong> or an <strong>XmlWritter, </strong>to provide infrastructure to write or read the XML file, and that&#8217;s all. Now we can serialize, into an XML file, any instance of any class tagged as <strong>DataContract</strong> and deserialize it from an XML file.</p>
<p>This is an example of using, in an Console Application we create an instance of <strong>Person </strong>class, set some data and we serialize using out <strong>ModelSerializer</strong>.</p>
<table cellspacing="2" cellpadding="0" width="100%" bgcolor="#3f3f3f" border="0">
<tbody>
<tr>
<td valign="top" width="400">
<pre><span style="color: #eaeaac"><span style="font-size: x-small;font-family: consolas"><font size="2">class </font></span></span><span style="color: #f0dfaf"><span style="font-size: x-small;font-family: consolas"><font size="2">Program
</font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">{
    </span><span style="color: #eaeaac">static void </span><span style="color: #dfdfbf">Main</span><span style="color: #dcdccc">(</span><span style="color: #eaeaac">string</span><span style="color: #dcdccc">[] </span><span style="color: #dfdfbf">args</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">)
    {
        </span><span style="color: #eaeaac">var </span><span style="color: #dfdfbf">person </span><span style="color: #dcdccc">= </span><span style="color: #eaeaac">new </span><span style="color: #f0dfaf">Person</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">()
        {
            </span><span style="color: #dfdfbf">Id </span><span style="color: #dcdccc">= </span><span style="color: #8acccf">1</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">,
            </span><span style="color: #dfdfbf">Name </span><span style="color: #dcdccc">= </span><span style="color: #c89191">&quot;Franz Xaver Sussmayr&quot;</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">,
        };

        </span><span style="color: #dfdfbf">person</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Address</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Add</span><span style="color: #dcdccc">(</span><span style="color: #eaeaac">new </span><span style="color: #f0dfaf">Address</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">()
        {
            </span><span style="color: #dfdfbf">Street </span><span style="color: #dcdccc">= </span><span style="color: #c89191">&quot;Schwanenstadt&quot;</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">,
            </span><span style="color: #dfdfbf">Number </span><span style="color: #dcdccc">= </span></font></span></span><span style="color: #8acccf"><span style="font-size: x-small;font-family: consolas"><font size="2">1766
        </font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">});

        </span><span style="color: #dfdfbf">person</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Address</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Add</span><span style="color: #dcdccc">(</span><span style="color: #eaeaac">new </span><span style="color: #f0dfaf">Address</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">()
        {
            </span><span style="color: #dfdfbf">Street </span><span style="color: #dcdccc">= </span><span style="color: #c89191">&quot;Vienna&quot;</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">,
            </span><span style="color: #dfdfbf">Number </span><span style="color: #dcdccc">= </span></font></span></span><span style="color: #8acccf"><span style="font-size: x-small;font-family: consolas"><font size="2">1803
        </font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">});

        </span><span style="color: #eaeaac">var </span><span style="color: #dfdfbf">serializer </span><span style="color: #dcdccc">= </span><span style="color: #eaeaac">new </span><span style="color: #f0dfaf">ModelSerializer</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">();

        </span><span style="color: #dfdfbf">serializer</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Serialize</span><span style="color: #dcdccc">&lt;</span><span style="color: #f0dfaf">Person</span><span style="color: #dcdccc">&gt;(</span><span style="color: #dfdfbf">person</span><span style="color: #dcdccc">, </span><span style="color: #c89191">&quot;C:/person.xml&quot;</span></font></span></span><span style="color: #dcdccc"><span style="font-size: x-small;font-family: consolas"><font size="2">);
    }
}</font></span></span></pre>
</td>
</tr>
</tbody>
</table>
<p>And the result is an <strong>person.xml </strong>file with this content:</p>
<table cellspacing="2" cellpadding="0" width="100%" bgcolor="#3f3f3f" border="0">
<tbody></tbody>
<tbody>
<tr>
<td valign="top" width="400">
<pre><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #efef8f">&lt;?xml </span><span style="color: #dfdfbf">version</span><span style="color: #efef8f">=</span><span style="color: #cc9393">&quot;1.0&quot; </span><span style="color: #dfdfbf">encoding</span><span style="color: #efef8f">=</span><span style="color: #cc9393">&quot;utf-8&quot;</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #efef8f">?&gt;
&lt;Person </span><span style="color: #dfdfbf">xmlns:i</span><span style="color: #efef8f">=</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #cc9393">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
        </span><span style="color: #dfdfbf">xmlns</span><span style="color: #efef8f">=</span><span style="color: #cc9393">&quot;http://schemas.datacontract.org/2004/07/WcfSerialization&quot;</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #efef8f"><font size="2">&gt;
</font></span></span></span></pre>
<p><font size="2"><br />
            <br /><font face="Consolas"></font></font></p>
<pre><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #efef8f">  &lt;Id&gt;</span><span style="color: #dcdccc">1</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #efef8f">&lt;/Id&gt;
  &lt;Name&gt;</span><span style="color: #dcdccc">Franz Xaver Sussmayr</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #efef8f"><font size="2">&lt;/Name&gt;
</font></span></span></span></pre>
<p><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #efef8f">&#160; &lt;Address&gt;<br />
                  <br />&#160;&#160;&#160; &lt;Address&gt;</p>
<p>&#160;&#160;&#160;&#160;&#160; &lt;Number&gt;</span><span style="color: #dcdccc">1766</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #efef8f">&lt;/Number&gt;<br />
                  <br />&#160;&#160;&#160;&#160;&#160; &lt;Street&gt;</span><span style="color: #dcdccc">Schwanenstadt</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #efef8f"><font size="2">&lt;/Street&gt;<br />
                  <br />&#160;&#160;&#160; &lt;/Address&gt;</font></span></span></span></p>
<pre><span style="font-size: x-small"><span style="font-family: consolas"><span style="color: #efef8f">
<font size="2">    &lt;Address&gt;
      &lt;Number&gt;</font></span><span style="color: #dcdccc"><font size="2">1803</font></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #efef8f">&lt;/Number&gt;
      &lt;Street&gt;</span><span style="color: #dcdccc">Vienna</span></font></span></span><span style="color: #efef8f"><span style="font-size: x-small;font-family: consolas"><font size="2">&lt;/Street&gt;
    &lt;/Address&gt;
  &lt;/Address&gt;</font></span></span></pre>
<p><span style="color: #efef8f"><span style="font-size: x-small;font-family: consolas"><font size="2">&lt;/Person&gt;</font></span></span></p>
</td>
</tr>
</tbody>
</table>
<p>To deserialize this file is even more easy&#8230;</p>
<table cellspacing="2" cellpadding="0" width="100%" bgcolor="#3f3f3f" border="0">
<tbody></tbody>
<tbody>
<tr>
<td valign="top" width="400">
<pre><span style="color: #eaeaac"><span style="font-size: x-small;font-family: consolas"><font size="2">class </font></span></span><span style="color: #f0dfaf"><span style="font-size: x-small;font-family: consolas"><font size="2">Program
</font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">{
    </span><span style="color: #eaeaac">static void </span><span style="color: #dfdfbf">Main</span><span style="color: #dcdccc">(</span><span style="color: #eaeaac">string</span><span style="color: #dcdccc">[] </span><span style="color: #dfdfbf">args</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">)
    {
        </span><span style="color: #eaeaac">var </span><span style="color: #dfdfbf">serializer </span><span style="color: #dcdccc">= </span><span style="color: #eaeaac">new </span><span style="color: #f0dfaf">ModelSerializer</span></font></span></span><span style="font-size: x-small"><span style="font-family: consolas"><font size="2"><span style="color: #dcdccc">();

        </span><span style="color: #eaeaac">var </span><span style="color: #dfdfbf">person </span><span style="color: #dcdccc">= </span><span style="color: #dfdfbf">serializer</span><span style="color: #dcdccc">.</span><span style="color: #dfdfbf">Deserialize</span><span style="color: #dcdccc">&lt;</span><span style="color: #f0dfaf">Person</span><span style="color: #dcdccc">&gt;(</span><span style="color: #c89191">&quot;C:/person.xml&quot;</span></font></span></span><span style="color: #dcdccc"><span style="font-size: x-small;font-family: consolas"><font size="2">);
    }
}</font></span></span></pre>
</td>
</tr>
</tbody>
</table>
<p><a href="http://blogs.southworks.net/lboffi/files/2008/08/quickwatch.jpg"><img height="401" alt="quickwatch" src="http://blogs.southworks.net/lboffi/files/2008/08/quickwatch-thumb.jpg" width="508" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.southworks.net/lboffi/2008/07/16/wcf-datacontract-serializer/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Service-oriented with WCF</title>
		<link>http://blogs.southworks.net/lboffi/2008/06/30/service-oriented-with-wcf-part-i/</link>
		<comments>http://blogs.southworks.net/lboffi/2008/06/30/service-oriented-with-wcf-part-i/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 04:52:25 +0000</pubDate>
		<dc:creator />
		
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/lboffi/?p=17</guid>
		<description><![CDATA[One of the things I really like about working at Southworks is that you have access to an incredible library where you can learn a lot, this is part of the Southworks&#8217; culture
This weekend I started reading Justin Smith&#8217;s book &#8220;Inside Windows Communication Foundation&#8221;.

I&#8217;ve finished the first part of the book, although I&#8217;ve worked in [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I really like about working at <a href="http://www.southworks.net">Southworks</a> is that you have access to an incredible library where you can learn a lot, this is part of the <a href="http://blogs.southworks.net/mszklanny/2008/06/02/inside-southworks-culture-first/">Southworks&#8217; culture</a></p>
<p>This weekend I started reading <strong>Justin Smith&#8217;s </strong>book &#8220;<strong>Inside Windows Communication Foundation&#8221;.</strong></p>
<p><img src="http://blogs.southworks.net/lboffi/files/2008/06/dsc070751.jpg" border="0" alt="" width="428" height="334" /></p>
<p>I&#8217;ve finished the first part of the book, although I&#8217;ve worked in service-oriented systems, I&#8217;ve learned new things about service-orientation and WCF.</p>
<p>Let&#8217;s start&#8230;</p>
<blockquote><p>WCF is the Microsoft&#8217;s API for creating service-oriented applications.</p>
<p> </p></blockquote>
<p>One of the things I really like about WCF, between others, is a &#8220;conceptual&#8221; feature: <span style="text-decoration: underline">WCF works as a &#8220;bridge&#8221; between object-oriented world and service-oriented world</span>. It means I can work in lovely my object-oriented world (having a very little considerations) and turn my application into service-oriented in a very easy way.</p>
<h2>Service Orientation</h2>
<blockquote><p><strong>In a nutshell, service orientation is an architectural style in witch distributed applications components are loosely coupled through contracts.</strong></p>
<p>Service-oriented applications describe the messages they interact with through contracts. These contracts must be expressed in a language and format easily understood by other applications, thereby reducing the number of dependencies on component implementation.</p></blockquote>
<p>I think is very clear, our system, distributed, connected by messages described by contracts, this made possible our components be loosely coupled. And lastly, I&#8217;d like to add that <span style="text-decoration: underline">Service Orientation just like Object Orientation is a paradigm that transcends vendors and technology boundaries</span>.</p>
<h2>An example&#8230;</h2>
<p>I like the definitions, but I&#8217;m a developer, so let&#8217;s take the definition to code.</p>
<h5> </h5>
<h3>The Contract</h3>
<p>As you can read in the service orientation definition the start point of our service-oriented application should be the contract.</p>
<p>The contract must define the messages in a language and format easily understood by other applications, as you can imagine XML is the natural choice.</p>
<p>Imagine a &#8220;to-do lists&#8221; service, and this being our task message definition contract:</p>
<p><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&lt;</span><span style="color: #a31515">Task</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
    &lt;</span><span style="color: #a31515">TaskId</span><span style="color: #0000ff">&gt;</span>xs:integer<span style="color: #0000ff">&lt;/</span><span style="color: #a31515">TaskId</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
    &lt;</span><span style="color: #a31515">Text</span><span style="color: #0000ff">&gt;</span>xs:string<span style="color: #0000ff">&lt;/</span><span style="color: #a31515">Text</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
    &lt;</span><span style="color: #a31515">IsCompleted</span><span style="color: #0000ff">&gt;</span>xs:boolean<span style="color: #0000ff">&lt;/</span><span style="color: #a31515">IsCompleted</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
&lt;/</span><span style="color: #a31515">Task</span><span style="color: #0000ff">&gt;</span></span></span></span></p>
<p>Sender and receiver must agree on what kind of messages they&#8217;re going to use, this is an example using <a href="http://www.w3.org/TR/soap/" target="_blank">SOAP</a> messages.</p>
<p><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&lt;</span><span style="color: #a31515">s:Envelope </span><span style="color: #ff0000">xmlns:s</span><span style="color: #0000ff">=</span>&#8220;<span style="color: #0000ff">http://www.w3.org/2003/05/soap-envelope</span>&#8221;<br />
            <span style="color: #ff0000">xmlns:wsa</span><span style="color: #0000ff">=</span>&#8220;<span style="color: #0000ff">http://schemas.xmlsoap.org/ws/2004/08/addressing</span>&#8220;</span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
  &lt;</span><span style="color: #a31515">s:Header</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
    &lt;</span><span style="color: #a31515">wsa:MessageID</span><span style="color: #0000ff">&gt;</span>1<span style="color: #0000ff">&lt;/</span><span style="color: #a31515">wsa:MessageID</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
    &lt;</span><span style="color: #a31515">wsa:Action </span><span style="color: #ff0000">s:mustUnderstand</span><span style="color: #0000ff">=</span>&#8220;<span style="color: #0000ff">1</span>&#8220;<span style="color: #0000ff">&gt;</span>urn:submitTask<span style="color: #0000ff">&lt;/</span><span style="color: #a31515">wsa:Action</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
    &lt;</span><span style="color: #a31515">wsa:ReplyTo</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
      &lt;</span><span style="color: #a31515">wsa:Address</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
        </span>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous<br />
      <span style="color: #0000ff">&lt;/</span><span style="color: #a31515">wsa:Address</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
    &lt;/</span><span style="color: #a31515">wsa:ReplyTo</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
    &lt;</span><span style="color: #a31515">wsa:To </span><span style="color: #ff0000">s:mustUnderstand</span><span style="color: #0000ff">=</span>&#8220;<span style="color: #0000ff">1</span>&#8220;<span style="color: #0000ff">&gt;</span>http://localhost:32677/Order<span style="color: #0000ff">&lt;/</span><span style="color: #a31515">wsa:To</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
  &lt;/</span><span style="color: #a31515">s:Header</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
  &lt;</span><span style="color: #a31515">s:Body</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
    &lt;</span><span style="color: #a31515">Task</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
      &lt;</span><span style="color: #a31515">TaskId</span><span style="color: #0000ff">&gt;</span>27<span style="color: #0000ff">&lt;/</span><span style="color: #a31515">TaskId</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
      &lt;</span><span style="color: #a31515">Text</span><span style="color: #0000ff">&gt;</span>Clean my room<span style="color: #0000ff">&lt;/</span><span style="color: #a31515">Text</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
      &lt;</span><span style="color: #a31515">IsCompleted</span><span style="color: #0000ff">&gt;</span>1<span style="color: #0000ff">&lt;/</span><span style="color: #a31515">IsCompleted</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
    &lt;/</span><span style="color: #a31515">Task</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
  &lt;/</span><span style="color: #a31515">s:Body</span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">&gt;<br />
&lt;/</span><span style="color: #a31515">s:Envelope</span><span style="color: #0000ff">&gt;</span></span></span></span></p>
<pre><span style="font-size: x-small"></span></pre>
<p>As you can see the example also uses <a href="http://www.w3.org/Submission/ws-addressing/" target="_blank">WS-Addressing</a> to indicate the target of the message.</p>
<p><span style="font-size: xx-small">(I am not going to explain </span><a href="http://www.w3.org/Submission/ws-addressing/" target="_blank"><span style="font-size: xx-small">WS-Addressing</span></a><span style="font-size: xx-small">, because my lack of time, if you hadn&#8217;t worked with webservices and WS-Addressing before you can read more about </span><a href="http://en.wikipedia.org/wiki/WS-Addressing" target="_blank"><span style="font-size: xx-small">WS-Addressing in wikipedia</span></a><span style="font-size: xx-small">.)</span></p>
<p>After we have our Task message contract defined, the next step is to define the endpoint that will receive the message, to do this we use <a href="http://www.w3.org/TR/wsdl">WSDL</a>.</p>
<p>Thanks god, or thanks to the WCF Team, WCF provides a way to express a contract in C# (or our favorite CLR compatible language).</p>
<blockquote><p><em>A contract expressed in C# can be turned into XSD-based and WSDL-based contracts on demand.</em></p></blockquote>
<p>If we choose to express our contracts in C#, we usually use Interfaces.</p>
<pre><span style="font-size: x-small"></span></pre>
<p> </p>
<pre><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #0000ff">namespace </span>SOApplication.Contracts
{
    <span style="color: #0000ff">using </span>System;
    <span style="color: #0000ff">using </span>System.ServiceModel;
    <span style="color: #0000ff">using </span>System.ServiceModel.Channels;

    [<span style="color: #2b91af">ServiceContract</span>(Namespace = <span style="color: #a31515">"http://services.taskmanager.com/TaskService"</span>)]
    <span style="color: #0000ff">public interface </span></span></span></span><span style="font-size: x-small"><span style="font-family: consolas"><span style="font-size: x-small"><span style="color: #2b91af">ITaskService
    </span>{
        [<span style="color: #2b91af">OperationContract</span>(Action=<span style="color: #a31515">"urn:SubmitTask"</span>)]
        <span style="color: #0000ff">void </span>SubmitTask(<span style="color: #2b91af">Message </span>task);
    }
}</span></span></span></pre>
<p> </p>
<pre></pre>
<p>As you can see, this is a normal C# interface. The attributes <strong>ServiceContract </strong>and <strong>OperationContract </strong>identifies the interface and the method as a Contracts, this contracts will be turned into an WSDL-based contract on demand.</p>
<p>Notice the type of <strong>task</strong>, the <strong>SubmitTask </strong>method parameter type is <strong>System.ServiceModel.Channels.Message </strong>this parameter represents any message that can be sent to a service.</p>
<p><strong>This contract now can be compiled into an assembly and distributed.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.southworks.net/lboffi/2008/06/30/service-oriented-with-wcf-part-i/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How To: LinqToSql from Windows PowerShell</title>
		<link>http://blogs.southworks.net/lboffi/2008/06/26/how-to-linqtosql-from-windows-powershell/</link>
		<comments>http://blogs.southworks.net/lboffi/2008/06/26/how-to-linqtosql-from-windows-powershell/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 00:08:59 +0000</pubDate>
		<dc:creator />
		
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/lboffi/2008/06/26/how-to-linqtosql-from-windows-powershell/</guid>
		<description><![CDATA[I think is very interesting&#8230;
In an Visual Studio Command Prompt, use sqlmetal tool&#160;to generate an C# wrapper file that will contain all the code you need to interact with your database, let&#8217;s supose PicturesDB. Notice I&#8217;ve added &#8220;/sprocs&#8221;, this means I also need the stored procedures.

\&#62;sqlmetal /server:.\SQLEXPRESS /database:PeopleDB /sprocs /code:db.cs&#160;
&#160;

Next step is to complie this [...]]]></description>
			<content:encoded><![CDATA[<p>I think is very interesting&#8230;</p>
<p>In an Visual Studio Command Prompt, use <strong><a href="http://msdn.microsoft.com/en-us/library/bb386987.aspx">sqlmetal tool</a>&nbsp;</strong>to generate an C# wrapper file that will contain all the code you need to interact with your database, let&#8217;s supose <strong>PicturesDB.</strong> Notice I&#8217;ve added &#8220;/sprocs&#8221;, this means I also need the stored procedures.</p>
<ol>
<p><font face="Consolas" size="2">\&gt;sqlmetal /server:.\SQLEXPRESS /database:PeopleDB /sprocs /code:db.cs</font>&nbsp;</p>
<p>&nbsp;</p>
</ol>
<p>Next step is to complie this file, to do this use the CS compiler. This compiles the <strong>db.cs </strong>file into an assembly called <strong>db.dll,</strong> accessible by PowerShell.</p>
<ol>
<p><font face="Consolas" size="2">\&gt;csc /target:libary db.cs</font></p>
</ol>
<p>&nbsp;</p>
<p>Now we have to load the assembly and use the generated class <strong>PeopleDB </strong>just like we do in C#. For this example we going to use an stored procedure called <strong>GetPeople</strong>.</p>
<ol>
<p><font face="Consolas" size="2">[Reflection.Assembly]::LoadFile(&#8217;C:\db.dll&#8217;)<br />$conn = &#8220;server=.\SQLEXPRESS;database=PicturesDB;Trusted_Connection=true&#8221;<br />$db = new-object dbMovies($conn)<br />$result = $db.GetPeople()<br />$result | format-list</font></p>
</ol>
<p><a href="http://blogs.southworks.net/lboffi/files/2008/06/pssp.jpg"><img height="314" alt="pssp" src="http://blogs.southworks.net/lboffi/files/2008/06/pssp-thumb.jpg" width="578" border="0"></a> </p>
<p>&nbsp;</p>
<p>I think this can be useful for deployment scripts or data base tests.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.southworks.net/lboffi/2008/06/26/how-to-linqtosql-from-windows-powershell/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sending eMails with System.Net.Mail.SmtpClient</title>
		<link>http://blogs.southworks.net/lboffi/2008/06/20/sending-emails-with-systemnetmailsmtpclient/</link>
		<comments>http://blogs.southworks.net/lboffi/2008/06/20/sending-emails-with-systemnetmailsmtpclient/#comments</comments>
		<pubDate>Fri, 20 Jun 2008 03:30:57 +0000</pubDate>
		<dc:creator />
		
		<category><![CDATA[Quick Code]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/lboffi/2008/06/20/sending-emails-with-systemnetmailsmtpclient/</guid>
		<description><![CDATA[This is a quickly sample of sending emails with SmtpClient class, in this example i&#8217;m using Gmail&#8217;s smtp server.
 
MailMessage mail = new MailMessage()
{
    From = new MailAddress(&#8220;user@gmail.com&#8221;, &#8220;[Name to Show]&#8220;), 
       Subject = &#8220;[Subject]&#8220;,
    IsBodyHtml = false,
    Body =&#8220;[Body]&#8221;
};
 
//To MailAddress
mail.To.Add(new MailAddress(&#8220;somebody@someplace.com&#8221;));
SmtpClient smtp = new SmtpClient(&#8220;smtp.gmail.com&#8221;, 587);
smtp.Credentials = new NetworkCredential(&#8220;[User]&#8220;, &#8220;[Passwd]&#8220;);

//Gmail smtp needs SSL
smtp.EnableSsl = [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quickly sample of sending emails with <strong>SmtpClient</strong> class, in this example i&#8217;m using <a href="http://mail.google.com">Gmail</a>&#8217;s smtp server.</p>
<p> </p>
<p><span style="font-size: x-small"><span style="font-family: Consolas"><span style="color: #2b91af">MailMessage </span>mail = <span style="color: blue">new </span><span style="color: #2b91af">MailMessage</span>()<br />
{<br />
    From = <span style="color: blue">new </span><span style="color: #2b91af">MailAddress</span>(<span style="color: #a31515">&#8220;user@gmail.com&#8221;</span>, <span style="color: #a31515">&#8220;[Name to Show]&#8220;</span>), </span></span><br />
       <span style="font-size: x-small"><span style="font-family: Consolas">Subject = <span style="color: #a31515">&#8220;[Subject]&#8220;</span>,<br />
    IsBodyHtml = <span style="color: blue">false</span>,<br />
    Body =</span></span><span style="font-size: x-small"><span style="font-family: Consolas"><span style="color: #a31515">&#8220;[Body]&#8221;<br />
</span>};</span></span></p>
<p><span style="font-size: x-small"><span style="font-family: Consolas"> </span></span></p>
<p><span style="font-size: x-small"><span style="font-family: Consolas"><span style="color: green">//To MailAddress<br />
</span>mail.To.Add(<span style="color: blue">new </span><span style="color: #2b91af">MailAddress</span>(<span style="color: #a31515">&#8220;somebody@someplace.com&#8221;</span>));</span></span></p>
<p><span style="font-size: x-small"><span style="font-family: Consolas"><span style="color: #2b91af">SmtpClient </span>smtp = <span style="color: blue">new </span><span style="color: #2b91af">SmtpClient</span>(<span style="color: #a31515">&#8220;smtp.gmail.com&#8221;</span>, 587);<br />
smtp.Credentials = <span style="color: blue">new </span><span style="color: #2b91af">NetworkCredential</span>(<span style="color: #a31515">&#8220;[User]&#8220;</span>, <span style="color: #a31515">&#8220;[Passwd]&#8220;</span>);</p>
<p></span></span></p>
<p><span style="font-size: x-small"><span style="font-family: Consolas"><span style="color: green">//Gmail smtp needs SSL<br />
</span>smtp.EnableSsl = <span style="color: blue">true</span>;</span></span></p>
<p><span style="font-size: x-small"><span style="font-family: Consolas"> </span></span></p>
<p><span style="font-size: x-small"><span style="font-family: Consolas"><span style="color: blue">try<br />
</span>{<br />
    smtp.Send(mail);<br />
}<br />
<span style="color: blue">catch </span>(<span style="color: #2b91af">Exception </span>ex)<br />
{<br />
   </span></span><span style="font-size: x-small"><span style="font-family: Consolas"><span style="color: green">//manage your exception&#8230;<br />
</span>}</span></span></p>
<p> </p>
<p>Don&#8217;t forget add the usings:</p>
<pre><span style="font-size: x-small"><span style="font-family: Consolas"><span style="color: blue">using </span>System.Net;
<span style="color: blue">using </span>System.Net.Mail;</span></span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p> </p>
<p>Thanks!,</p>
<p>Lean.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.southworks.net/lboffi/2008/06/20/sending-emails-with-systemnetmailsmtpclient/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Calling an SP from Windows PowerShell</title>
		<link>http://blogs.southworks.net/lboffi/2008/06/16/calling-an-sp-from-windows-powershell/</link>
		<comments>http://blogs.southworks.net/lboffi/2008/06/16/calling-an-sp-from-windows-powershell/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 18:31:29 +0000</pubDate>
		<dc:creator />
		
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/lboffi/2008/06/16/calling-an-sp-from-windows-powershell/</guid>
		<description><![CDATA[The next PowerShell code is an example to call an Stored Procedure from Windows PowerShell&#8230;
Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8221; Write-Host &#8220;DataScript Started&#8230;OK&#8221; Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8221;
$connectionString = &#8220;Server=localhost;DataBase=PictureDB;Integrated Security=SSPI&#8221;
$conn = new-Object System.Data.SqlClient.SqlConnection($connectionString) $conn.Open()
Write-Host &#8220;Connection Opened&#8230;&#8221; Write-Host &#8220;&#8221;
[int] $rowCount = 0
$cmd = new-Object System.Data.SqlClient.SqlCommand(&#8221;InsertPicture&#8221;, $conn) $cmd.CommandType = [System.Data.CommandType]&#8216;StoredProcedure&#8217;
$cmd.Parameters.Clear()
$cmd.Parameters.Add(&#8221;@PictureId&#8221;, [System.Guid]::NewGuid().ToString()) &#124; out-null
$cmd.Parameters.Add(&#8221;@Text&#8221;, &#8220;ISO Party&#8221;) &#124; out-null $cmd.Parameters.Add(&#8221;@SubmittedOn&#8221;, [System.DateTime]::Now) &#124; out-null
$cmd.Parameters.Add(&#8221;@Image&#8221;, [System.IO.File]::ReadAllBytes(&#8221;pictures/party001.jpg&#8221;)) &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>The next PowerShell code is an example to call an Stored Procedure from Windows PowerShell&#8230;</p>
<p><font face="Consolas" size="2">Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8221; <br />Write-Host &#8220;DataScript Started&#8230;OK&#8221; <br />Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8221;</font></p>
<p><font face="Consolas" size="2">$connectionString = &#8220;Server=localhost;DataBase=PictureDB;Integrated Security=SSPI&#8221;</font></p>
<p><font face="Consolas" size="2">$conn = new-Object System.Data.SqlClient.SqlConnection($connectionString) <br />$conn.Open()</font></p>
<p><font face="Consolas" size="2">Write-Host &#8220;Connection Opened&#8230;&#8221; <br />Write-Host &#8220;&#8221;</font></p>
<p><font face="Consolas" size="2">[int] $rowCount = 0</font></p>
<p><font face="Consolas" size="2">$cmd = new-Object System.Data.SqlClient.SqlCommand(&#8221;InsertPicture&#8221;, $conn) <br />$cmd.CommandType = [System.Data.CommandType]&#8216;StoredProcedure&#8217;</font></p>
<p><font face="Consolas" size="2">$cmd.Parameters.Clear()</font></p>
<p><font face="Consolas" size="2">$cmd.Parameters.Add(&#8221;@PictureId&#8221;, <br />[System.Guid]::NewGuid().ToString()) | out-null</font></p>
<p><font face="Consolas" size="2">$cmd.Parameters.Add(&#8221;@Text&#8221;, &#8220;ISO Party&#8221;) | out-null <br />$cmd.Parameters.Add(&#8221;@SubmittedOn&#8221;, [System.DateTime]::Now) | out-null</font></p>
<p><font face="Consolas" size="2">$cmd.Parameters.Add(&#8221;@Image&#8221;, <br />[System.IO.File]::ReadAllBytes(&#8221;pictures/party001.jpg&#8221;)) | out-null</font></p>
<p><font face="Consolas" size="2">Write-Host &#8220;Inserting picture&#8230;&#8221;</font></p>
<p><font face="Consolas" size="2">$rowCount = $cmd.ExecuteNonQuery()</font></p>
<p><font face="Consolas" size="2">$cmd.Dispose()</font></p>
<p><font face="Consolas" size="2">Write-Host $rowCount &#8220;Rows acfected!&#8221;</font></p>
<p><font face="Consolas" size="2">$conn.Close() <br />$conn.Dispose()</font></p>
<p><font face="Consolas" size="2">Write-Host &#8220;&#8221; <br />Write-Host &#8220;Connection Closed.&#8221;</font></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.southworks.net/lboffi/2008/06/16/calling-an-sp-from-windows-powershell/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
