<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><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" version="2.0">

<channel>
	<title>Developing For .NET</title>
	
	<link>http://www.developingfor.net</link>
	<description>Real World .NET Methods, Tricks, and Examples</description>
	<pubDate>Tue, 25 Nov 2008 00:07:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/DevelopingForDotNet" type="application/rss+xml" /><item>
		<title>WCF, Silverlight 2, and IIS 6.0</title>
		<link>http://www.developingfor.net/silverlight/wcf-silverlight-2-and-iis-60.html</link>
		<comments>http://www.developingfor.net/silverlight/wcf-silverlight-2-and-iis-60.html#comments</comments>
		<pubDate>Mon, 24 Nov 2008 23:59:15 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
		
		<category><![CDATA[IIS 6.0]]></category>

		<category><![CDATA[Silverlight]]></category>

		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=184</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/silverlight/wcf-silverlight-2-and-iis-60.html";</script>var dzone_style="2";I&#8217;m ready to begin my first production Silverlight 2 project, so I needed to learn how to make a data driven Silverlight application.  I pretty much already knew that the answer would involve WCF, but as I do not have much experience with such things I was not sure what to expect.  [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/silverlight/wcf-silverlight-2-and-iis-60.html";</script><script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>I&#8217;m ready to begin my first production Silverlight 2 project, so I needed to learn how to make a data driven Silverlight application.  I pretty much already knew that the answer would involve WCF, but as I do not have much experience with such things I was not sure what to expect.  I had written several Web Services in PHP using NuSOAP, but I knew basically nothing about WCF or IIS hosting of web services. So, towards the goal of understanding what all the pieces are and how they fit together, I began my research.</p>
<p><strong>Getting Started with WCF</strong></p>
<p>As an old procedural midrange programmer, I always like to start with the data, so the WCF end was where I chose to begin.  I tried watching <a title="Michele Bustamante" href="http://www.dasblonde.net/" target="_blank">Michele Bustamante&#8217;s</a> <a title="15 part video series on WCF" href="http://www.dasblonde.net/2007/06/24/WCFWebcastSeries.aspx" target="_blank">15 part video series on WCF</a>, but half way through the second video my eyes glazed over and the drool was beginning to stain my shirt.  While I understand she is a giant in the field, this series was not for the rank amateur.</p>
<p>I surfed around Google for a while and came up with several decent examples and a couple of videos.  At some point, once I understood the basics, I stumbled across an example of the new Silverlight-enabled WCF Service item type which greatly simplified things. I hooked up a Linq to SQL project to my WCF service and was able to return Linq classes (or subsets as necessary).</p>
<p>I was able to hook up a simple WCF test inside a Silverlight 2 application and consume my new Services.  All was well, but I had done everything inside the Silverlight project.  It made more sense to me to break the WCF out into its own Solution.  To accomplish this, I followed these steps:</p>
<ol>
<li>Create a WCF Service Application</li>
<li>Delete the default Service1 files</li>
<li>Add a new &#8220;Silverlight-enabled WCF Service&#8221; item</li>
<li>Create the services as needed</li>
</ol>
<p><strong>Deploying the Service to IIS 6.0</strong></p>
<p>I&#8217;m unfortunately still stuck with IIS 6.0.  I don&#8217;t know if the experience is any different on IIS 7.0, but I went through some trials getting this to work properly.  To be fair, I&#8217;m sure that most of the trials were caused by my own ignorance.</p>
<p>At first, I was trying to deploy the Services as part of an existing ASP.NET application.  This got hairy pretty quickly, since I wasn&#8217;t sure how to properly merge the two projects together on the server.  I tried deploying the Services to a subdirectory, but I could never get it to work.  At that point I decided that it would probably be best if I put the services on their own subdomain, so I created a new subdomain for the Services.</p>
<p>I was able to deploy the Service site to the new subdomain and the WSDL page displayed properly.  (Actually, it didn&#8217;t right away: I had apparently screwed something up trying to merge it with the other ASP.NET application, so I recreated the Service application from scratch which only took a few minutes.  It was that page that displayed properly.)</p>
<p>So at this point I thought I should have been able to simply switch out my Service Reference in my Silverlight application, but it didn&#8217;t work.  I messed around with it but couldn&#8217;t get it to respond.  When I ran the application in debug, I received a message indicating that the WCF Service was not configured for cross domain access.  Since the Service was now live on the domain but my application was running on localhost, my requests were being rejected by the server.  To solve this, I added a <a title="MSDN client access policy xml" href="http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx" target="_blank">clientaccesspolicy.xml</a> file.  At this point, the test Silverlight application running on my local machine began functioning again.</p>
<p><strong>Deploying the Silverlight Application</strong></p>
<p>Now, with my Service installed, configured, and running as desired, and with my Silverlight 2 application consuming that Service, I figured I was ready to deploy it to the server.  I created my new ASP.NET web site on IIS 6.0 and deployed the Silverlight application&#8217;s test ASP.NET page.  I pointed my browser to the test page and&#8230; <em>nothing</em>.</p>
<p>And by nothing, I mean I received the dreaded blank page.  Even worse, when I tried to right-click to view the source, all I got was the &#8220;Silverlight Configuration&#8221; prompt.  At first I was really bummed, but then I realized that if I was getting the Silverlight prompt, then that meant the browser recognized my content as Silverlight!  I was actually closer to success than I originally imagined!</p>
<p>Once more unto the Google breach, and I found that, at least in IIS 6.0, you have to configure a MIME type for .xap files!  I navigated to the MIME settings on my Silverlight domain and added a Type for extension &#8220;.xap&#8221; with a content type of &#8220;application/x-silverlight-app&#8221;.  I restarted the web site and went to my page and Viola!  I had a Silverlight 2 application running on IIS 6.0 that consumed WCF Services!</p>
<p><strong>What&#8217;s next</strong></p>
<p>So now that I have the basic structure down, I have a bit of work left to do.  First, I need to test all my Services.  Then I need to read up on performance for WCF: I believe there are some lazy loading techniques I can use to make sure my users are getting immediate access and not waiting around for a bunch of data to load.  After that, it will be back to Blend 2 for some serious design work.  I don&#8217;t have anything particularly juicy in mind for this application, but I do want something a little beyond the ordinary.  Along the way, I&#8217;m hoping to upgrade to Server 2008, Sql Server 2008, and IIS 7.0.  And in January I am taking Computer Graphics classes at the local community college.  All in all, it looks like I&#8217;m going to be having a lot of fun in the near future!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/silverlight/wcf-silverlight-2-and-iis-60.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Star Trek Movie Trailer</title>
		<link>http://www.developingfor.net/miscellaneous/star-trek-movie-trailer.html</link>
		<comments>http://www.developingfor.net/miscellaneous/star-trek-movie-trailer.html#comments</comments>
		<pubDate>Thu, 20 Nov 2008 16:44:56 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
		
		<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=179</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/miscellaneous/star-trek-movie-trailer.html";</script>var dzone_style="2";OK, I know, absolutely nothing to do with .NET, but I&#8217;m sure my fellow Trekkers out there will appreciate this.  There is an awesome new trailer on http://www.startrekmovie.com/ for the next Star Trek installment.  And I must say I am very impressed!
And, the site itself is very impressive.  It is a [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/miscellaneous/star-trek-movie-trailer.html";</script><script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>OK, I know, absolutely nothing to do with .NET, but I&#8217;m sure my fellow Trekkers out there will appreciate this.  There is an awesome new trailer on <a title="Star Trek Movie Official Site" href="http://www.startrekmovie.com/" target="_blank">http://www.startrekmovie.com/</a> for the next Star Trek installment.  And I must say I am very impressed!</p>
<p>And, the site itself is very impressive.  It is a Flash 10 site that has some great effects.  I used to see a site like this and believe that it was out of my reach as a developer, after all I&#8217;m no graphic artist.  But these days, when I see something like this I start to think that I could get results like this in Silverlight.  Personally, I&#8217;m starting to get very excited about web development again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/miscellaneous/star-trek-movie-trailer.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>WPF Visual State Manager</title>
		<link>http://www.developingfor.net/wpf/wpf-visual-state-manager.html</link>
		<comments>http://www.developingfor.net/wpf/wpf-visual-state-manager.html#comments</comments>
		<pubDate>Fri, 07 Nov 2008 21:29:28 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
		
		<category><![CDATA[Blend]]></category>

		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=172</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/wpf/wpf-visual-state-manager.html";</script>var dzone_style="2";Last night at RVNUG, a friend of mine pointed me to The WPF Toolkit.  The toolkit is a collection of controls and features that extend the current WPF offering from Microsoft.  Chief among these is the DataGrid control, but something more appealing caught my eye: Visual State Manager.
Basically, the VSM is a [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/wpf/wpf-visual-state-manager.html";</script><script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>Last night at <a title="RVNUG" href="http://www.rvnug.org" target="_blank">RVNUG</a>, a friend of mine pointed me to <a title="WPF Toolkit" href="http://www.codeplex.com/wpf" target="_blank">The WPF Toolkit</a>.  The toolkit is a collection of controls and features that extend the current WPF offering from Microsoft.  Chief among these is the DataGrid control, but something more appealing caught my eye: Visual State Manager.</p>
<p>Basically, the VSM is a very easy to use feature of Blend 2 SP1 that supports Silverlight 2.  It allows the developer to easily set the visual state of user controls and control templates based on the current state of the control, such as MouseOver and Pressed.  I had seen this when I was exploring Silverlight 2 in Blend 2, but I&#8217;ve been focusing on WPF and was curious as to why I didn&#8217;t have the same functionality I had seen in Silverlight. Of course, now I know: VSM is currently only included as part of Blend 2 for Silverlight 2 development.  But, if you install the WPF Toolkit and follow the instructions in the link above to update your Registry, you can gain access to the same basic functionality for WPF Applications.</p>
<p><strong>Using VSM in WPF<br />
</strong></p>
<p>Previously, these state changes could be accomplished using Storyboards and Timelines, and then assigning their beginning and ending to Triggers. The Timeline tool in Blend is robust and feature rich, but I think for a non-graphically oriented developer it can be more than a little daunting. And it seems to be overkill for simple animations. That&#8217;s where VSM comes in: it greatly simplifies the task of adding small animations to element states.</p>
<p>The Silverlight implementation is very nice and intuitive right out of the box: the states are already defined and all you have to do is activate one and make your changes to the art board.  Unfortunately, the current version for WPF is not as straightforward.  In WPF, once you have the State manager visible, you have to create the State Groups and define the Visual States you wish to modify.  Once I figured out what was going on, this is not painful by any means, but it took some trial and error to get it working right.</p>
<p>So first things first, we need something that VSM can interact with.  Since VSM cannot be applied to the default template of a control, we need to create our own.  For this article, I created a button and then created an empty template.  Once you create the template, either by &#8216;edit a copy&#8217; or &#8216;create empty&#8217;, the States Manager will appear under the Triggers Manager on the left hand pane.  At this point, the only item visible in the States Manager is Base.  You can go ahead and create the default look of your template at this point.</p>
<p><strong>Set up the State Manager pane</strong></p>
<p>To begin with we need a Visual State Group to hold our Visual States.  In the Top Border of the States Manager pane on the far right side is a small icon with a plus sign on it.  Hovering over it will reveal that this is the &#8220;Add state group tool.  Pushing it will create a new Visual State Group header under Base.  Click on the title (VisualStateGroup) and rename it as you see fit.  I&#8217;m not sure that the group names matter, but to be on the safe side I followed the same scheme that Silverlight reveals and called my first one &#8220;CommonStates&#8221;.</p>
<p>Now that we have a group to hold our collection of Visual States, we can start adding states.  On the CommonStates header bar is another icon with a plus symbol: this is the &#8220;Add state&#8221; button, so press it to add a new state.  Rename VisualState to the desired state.  The state names do matter if we are to get the desired result, so I added three typical states: Normal, MouseOver, and Pressed.</p>
<p><strong>Altered States<br />
</strong></p>
<p>Now that we have all the missing pieces defined, we can use them just as we do in Silverlight 2. Clicking on the desired state in the State Manager pane will turn on State Recording [as indicated by the red border around the art board and the header message "State recording is on"].  Now you can easily adjust the display elements of the content to whatever you want them to be at that particular state.  A classic example would be brightening a button on MouseOver.</p>
<p>When you are done editing the visual elements, click on Base in the State Manager pane to exit state recording mode.  It is important that you do this, because otherwise you could easily alter just a given state when you think you are altering the control template itself.  Take it from me, this is very frustrating when you do not receive the results you expect.  And then, of course, to correct it you need to back all of your changes out and reapply them outside of state recording mode.</p>
<p><strong>Adding transitions</strong></p>
<p>If you have done all of the above, your button should be changing its visual appearance when you mouse over or press the button.  You may think this is the end, but wait, there&#8217;s more!  Leaving it as above will force the change from one state to another to happen immediately.  While we have become accustomed to such UI, it is not the most pleasing effect.  Instead, users react much better to very slight, more realistic animations.  In other words our users will find our software more appealing if it takes a little time to change from one state to another.  These quick, smooth changes from one state to another are very short and simple animations called &#8220;Transitions&#8221;.</p>
<p>To add a Transition, find the Visual State (such as &#8220;MouseOver&#8221;) in the State Manager pane and look to the right side of the header bar.  There you will find an arrow icon adorned with a plus symbol (notice a pattern developing here?)  Click on that and a helper window will appear with a collection of Transitions you can modify.  In my case, I chose the two with the &#8216;*&#8217;.  The one with the * on the left side indicates the transition from any other state to the selected state, and the one with the * on the right indicates the transition from the selected state to any other state.</p>
<p>Clicking on the desired Transition will add it beneath the selected state.  On the Transition you will find a text box that lets you enter the desired amount of time you wish the particular Transition to take.  The available range is 0 to 1 second.  It doesn&#8217;t take much for our Transition to have the desired effect, so try .1 or .2s at first to get the feel for it, then adjust as you desire.</p>
<p><strong>Conclusions</strong></p>
<p>Now when you run your project, you should detect the pleasing effects of Transitions. Overall, I find this much much easier than Storyboards and traditional animations.  I&#8217;m sure that eventually the tooling for WPF Applications will improve to match what is in Silverlight, but overall it is a minor complaint.  I want to thank the CodePlex guys for letting us in on this great secret!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/wpf/wpf-visual-state-manager.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>My first real WPF and Blend 2 application</title>
		<link>http://www.developingfor.net/c-30/my-first-real-wpf-and-blend-2-application.html</link>
		<comments>http://www.developingfor.net/c-30/my-first-real-wpf-and-blend-2-application.html#comments</comments>
		<pubDate>Tue, 21 Oct 2008 21:51:17 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
		
		<category><![CDATA[.NET 3.5]]></category>

		<category><![CDATA[Blend]]></category>

		<category><![CDATA[C# 3.0]]></category>

		<category><![CDATA[Expression]]></category>

		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=168</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/c-30/my-first-real-wpf-and-blend-2-application.html";</script>var dzone_style="2";I&#8217;ve been familiar with WPF since December 2006 and the release of C# 3.0, and I&#8217;ve had Expression Suite installed for almost a year.  While I&#8217;ve toyed with it here and there, I have never devoted the time and effort necessary to really begin to become proficient.
However, since last week&#8217;s Silverlight 2.0 release, [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/c-30/my-first-real-wpf-and-blend-2-application.html";</script><script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>I&#8217;ve been familiar with WPF since December 2006 and the release of C# 3.0, and I&#8217;ve had Expression Suite installed for almost a year.  While I&#8217;ve toyed with it here and there, I have never devoted the time and effort necessary to really begin to become proficient.</p>
<p>However, since last week&#8217;s Silverlight 2.0 release, I have been burying myself again in learning new technologies.  I finally decided to take the plunge, so I <a title="Silverlight Get Started page" href="http://silverlight.net/GetStarted/" target="_blank">installed Silverlight 2.0</a>, the Visual Studio updates, and upgraded to Expression Suite 2 SP1.  I spent a couple of days going through <a title="ScottGu Silverlight tutorial" href="http://weblogs.asp.net/scottgu/pages/silverlight-2-end-to-end-tutorial-building-a-digg-search-client.aspx" target="_blank">ScottGu&#8217;s tutorials</a> and some others on <a title="Silverlight Homepage" href="http://silverlight.net/" target="_blank">Silverlight.net</a>.  I followed along and built the samples, some in Visual Studio and some in Blend.</p>
<p>Most of these have been around for a while, so I&#8217;m not claiming any kind of leading edge stuff here.  What I wanted to do was to share some of the insights I&#8217;ve had in attempting this project.</p>
<p><strong>What&#8217;s the big deal</strong></p>
<p>XAML marks a sea change in how user interfaces are developed.  The end result of XAML is still .NET objects, and as such they can be created and managed programmaticaly, but the ability to simply describe what you want is very attractive.  For a long time, I did not like XAML itself, and one of my reasons for putting off learning WPF was that I wanted to wait until something like Blend made all XAML interaction obsolete.  After diving in for a few days, I no longer feel that way, but I&#8217;ll share more about that later.</p>
<p>What really makes all this so attractive is the ability to do basically whatever I can imagine for an interface.  More importantly, I can do it without a ton of hand coded control drawing, something I never liked doing in the first place.  The behavior of a control truly is separate from its presentation, and the presentation can be altered or replaced in any number of ways.  In other words, you can achieve some pretty cool effects with a reasonably small effort.</p>
<p><strong>Visual Studio or Blend?</strong></p>
<p>I&#8217;ve been having an ongoing discussion with a friend of mine at RVNUG about the usefulness of writing WPF applications within Visual Studio.  Having seen some demos and had some training on Blend, I was staunchly in the Blend corner on this one.  While you can drag and drop controls in Visual Studio, it takes a lot of hands on XAML coding to get anything more than a rudimentary window up and running.  As I mentioned previously, after seeing some XAML presentations I really wanted to avoid that as much as possible, which is what makes Blend so intriguing.</p>
<p>But, having gone through ScottGu&#8217;s Silverlight tutorial and building an application in Visual Studio, I have a better appreciation for it now.  One thing I do like about using Visual Studio is that it is keyboard centric.  As a classic Midrange developer I have always shied away from using the mouse as much as possible, so it appeals to my keyboard-philia.  And of course, Intellisense is still <em>the</em> killer feature and makes it much more palatable.  Also, as a seasoned and grizzled web developer who still likes the occasional dip into VI and Notepad, it only took a little time with XAML to feel comfortable with what was going on.  Anyone familiar with XHTML and CSS should find XAML completely doable.  It is, of course, a lot more complex, with numerous options and quirks, but it is still familiar territory.</p>
<p>Now, all that being said, I still prefer Blend 5 to 1 over Visual Studio for Visual XAML development.  I have only run into a few things that I couldn&#8217;t accomplish easily through Blend, and I&#8217;m new enough to it that I still chalk it up to just not knowing the tool well enough.  Applying and developing styles is still one of these areas: I so far have not figured out how to do them in Blend, so I revert to XAML editing.</p>
<p>Which brings me to my question of the day: &#8220;Should I use Visual Studio or Blend?&#8221;  The answer is a resounding &#8220;both!&#8221;  OK, I&#8217;m sure you saw that one coming, but let me explain my position.  If you are a developer, there is no question that you are going to use Visual Studio.  After all, it is our bread and butter, and all the real code will still be developed in our beloved IDE.  But designing serious WPF solutions in Visual Studio would be far too painful, even with great Intellisense support.  There are simply too many options to have to code them by hand.</p>
<p>It reminds me of my first Windows application: a Java Swing application that I<em> wrote in Wordpad. </em>Believe me, the pain of that experience made me instantly recognize the value of Visual Studio and is largely responsible for my shift to Microsoft technologies. On the same order, as soon as I saw Blend I knew that this was the tool I needed to design good WPF applications.  So, for layout and Visual Tree management, use Blend.  When you find a problem that you think you must solve using XAML editing, switch over to Visual Studio and take advantage of Intellisense, which Blend does not have.</p>
<p><strong>Quirks</strong></p>
<p>A couple of things so far have jumped out at me.  While Blend and Visual Studio do a pretty good job of keeping each other in synch, there are a couple of irregularities.</p>
<p>The first real problem I had was in adding existing projects to my solution in Visual Studio.  I started my solution in Visual Studio and then opened it up in Blend to work on the design.  Later in the same session, I went back to Visual Studio and added several projects.  Now that I had some CLR objects to work with, I wanted to try Data Binding, so I followed one of the online tutorials but no joy.  No matter what I did, I could not get Blend to find the objects.  Every time I tried, I received a slew of &#8220;file could not be located&#8221; errors.  Finally, I restarted Blend and when I opened my solution, there the missing objects were.</p>
<p>Second, there have been several times when I&#8217;m not sure that I am being properly prompted to reload.  I could be imagining it, but I feel pretty strongly that I have made changes in one without being prompted by the other to reload them.  Perhaps this is just a matter of timing Saves.</p>
<p><strong>Conclusion</strong></p>
<p>Well, I don&#8217;t really have any as of yet.  I do think that a lot of developers are going to struggle against the designer learning curve, yours truly included.  But I think in the long run we will be much better off.  So far, I am pleased with my efforts.  I like the combination of resources the two applications provide me, and I amd getting more comfortable in deciding which to use for certain scenarios.</p>
<p>I&#8217;m not quite ready for a tutorial series, but I will try to share some of my learning with you all as I go.  In the meantime, give it a try yourself and let us know what you think.  Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/c-30/my-first-real-wpf-and-blend-2-application.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Storing an Image in an XML file</title>
		<link>http://www.developingfor.net/net/storing-an-image-in-an-xml-file.html</link>
		<comments>http://www.developingfor.net/net/storing-an-image-in-an-xml-file.html#comments</comments>
		<pubDate>Wed, 01 Oct 2008 16:29:06 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=155</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/net/storing-an-image-in-an-xml-file.html";</script>var dzone_style="2";I recently had a project that required a custom subset of data from a database be stored in an XML file.  Each &#8220;row&#8221; of data also had a related image on a separate server.  The project required that both the data and the image be transferred to a client for subsequent consumption [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/net/storing-an-image-in-an-xml-file.html";</script><script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>I recently had a project that required a custom subset of data from a database be stored in an XML file.  Each &#8220;row&#8221; of data also had a related image on a separate server.  The project required that both the data and the image be transferred to a client for subsequent consumption by another program.  In designing the project, it seemed unnecessarily complex to transport the data and the images as separate entities.  Mostly the problem was that this process would simply add more moving parts, which would add to the complexity and increase the probability of &#8220;user inspired difficulties.&#8221;</p>
<p>Since both the data and the images were to be consumed by the same process, it appeared logical to embed the Image objects directly in the XML file as part of the data description.  I found several examples on the web and eventually hobbled together my own version.</p>
<p><strong>Saving the Image to XML</strong></p>
<p>Since XML is ultimately just a formatted text file, the first step is to find a way to represent the Image object as text.</p>
<div class="dean_ch" style="white-space: nowrap;">Bitmap bmp = new Bitmap<span class="br0">&#40;</span>imageFileName<span class="br0">&#41;</span>;<br />
TypeConverter converter = TypeDescriptor.<span class="me1">GetConverter</span><span class="br0">&#40;</span>typeof<span class="br0">&#40;</span>Bitmap<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
XElement img = new XElement<span class="br0">&#40;</span><span class="st0">&quot;image&quot;</span>,<br />
&nbsp; &nbsp; Convert.<span class="me1">ToBase64String</span><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>byte<span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>converter.<span class="me1">ConvertTo</span><span class="br0">&#40;</span>bmp, typeof<span class="br0">&#40;</span>byte<span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
element.<span class="me1">Add</span><span class="br0">&#40;</span>img<span class="br0">&#41;</span>;</div>
<p>There are several things going on here.  We want to convert the element to a <em>byte[]</em> so that we can extract a string representation of the object.  To do this we create a <em>TypeConverter</em> object over the <em>Bitmap</em> type.  Now we can use the <em>TypeConverter</em> to convert the <em>Bitmap</em> to a <em>byte[]</em>. Now, to properly encode the <em>byte[] </em>for writing to the XML file as a string, we convert it to a <a title="Wikipedia Base64" href="http://en.wikipedia.org/wiki/Base64" target="_blank">Base64</a> String.</p>
<p><strong>Reading the Image from the XML file</strong></p>
<p>Now that we have the <em>Bitmap</em> as part of our XML file, we need a way to read the Base64 String back into a <em>Bitmap</em> object:</p>
<div class="dean_ch" style="white-space: nowrap;"><span class="kw4">string</span> val = currentXml.<span class="me1">Element</span><span class="br0">&#40;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#41;</span>.<span class="me1">Value</span>;<br />
byte<span class="br0">&#91;</span><span class="br0">&#93;</span> bytes = Convert.<span class="me1">FromBase64String</span><span class="br0">&#40;</span>val<span class="br0">&#41;</span>;<br />
MemoryStream mem = new MemoryStream<span class="br0">&#40;</span>bytes<span class="br0">&#41;</span>;<br />
Bitmap bmp2 = new Bitmap<span class="br0">&#40;</span>mem<span class="br0">&#41;</span>;</div>
<p>In this example, we retrieve the XML text, convert it to a <em>byte[]</em> using <em>Convert.FromBase64String()</em>, use that to create a <em>MemoryStream</em>, and finally use the <em>MemoryStream</em> to create the <em>Bitmap</em>.  Naturally, you can make this more concise:</p>
<div class="dean_ch" style="white-space: nowrap;">Bitmap bmp = new Bitmap<span class="br0">&#40;</span>new MemoryStream<span class="br0">&#40;</span>Convert.<span class="me1">FromBase64String</span><span class="br0">&#40;</span>currentXml.<span class="me1">Element</span><span class="br0">&#40;</span><span class="st0">&quot;image&quot;</span><span class="br0">&#41;</span>.<span class="me1">Value</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
<p><strong>Wrapping it up</strong></p>
<p>I&#8217;m a novice when it comes to encryption and such things, so I&#8217;m not claiming that this is the best solution.  It did work and the application is functioning as designed, but I&#8217;d like to get some feedback about this method, comments, alternatives, etc. If there is a problem with this solution or a better way to do it, please comment below.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/net/storing-an-image-in-an-xml-file.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Live Blogging - MSDN Mid-Atlantic Roadshow</title>
		<link>http://www.developingfor.net/net/live-blogging-msdn-mid-atlantic-roadshow.html</link>
		<comments>http://www.developingfor.net/net/live-blogging-msdn-mid-atlantic-roadshow.html#comments</comments>
		<pubDate>Tue, 30 Sep 2008 15:56:18 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[.NET 3.5]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[ASP.NET MVC]]></category>

		<category><![CDATA[MSDN]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=144</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/net/live-blogging-msdn-mid-atlantic-roadshow.html";</script>var dzone_style="2";Today I am in Roanoke, VA at the MSDN Mid-Atlantic Roadshow.  This Microsoft event highlights Web development and .NET 3.5.
Web Development Basics - 9am

Presented by Andrew Duthie, Microsoft Technology Evangelist.  Andrew presents a nice history and overview of web development, from HTML/XHTML, Classic ASP, and up to ASP.NET.  It definitely confirms [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/net/live-blogging-msdn-mid-atlantic-roadshow.html";</script><script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>Today I am in Roanoke, VA at the MSDN Mid-Atlantic Roadshow.  This Microsoft event highlights Web development and .NET 3.5.</p>
<p><strong>Web Development Basics - 9am<br />
</strong></p>
<p>Presented by <a title="Andrew Duthie" href="http://blogs.msdn.com/gduthie" target="_blank">Andrew Duthie</a>, Microsoft Technology Evangelist.  Andrew presents a nice history and overview of web development, from HTML/XHTML, Classic ASP, and up to ASP.NET.  It definitely confirms my opinion that I am glad I never was a Classic ASP developer!</p>
<p>He discussed Postback and ViewState, (my least favorite features of ASP.NET and hence my appreciation of ASP.NET MVC.)  I know this is not a popular ASP.NET view point, but it makes it difficult for traditional web developers like myself to step into an ASP.NET role.  One thing he mentioned was that you can disable ViewState for particular controls, for performance reasons.  You would only do this if the element was for display only.</p>
<p>He also discussed one of my favorite features, Master Pages.  I have long used this same concept in PHP development and I immediately recognized it in ASP.NET.</p>
<p>Note to self: learn about Membership Profiles.  I&#8217;ve been developing my own because I am connecting to a non-standard data source (IBM iSeries DB2).  Andrew said you can write your own custom backend but still use the built in Profile features.</p>
<p>DataBinding Demo: he showed a typical GridView Control bound to a SqlDataSource.  &#8220;Declarative Data Binding&#8221; - there is no executable code that drives the GridView, it is all expressed in the ASPX.  It is fast and easy to develop, but you still have the option to develop your own binding for more control.</p>
<p>Web Services: ASMX and WCF Services both supported.  ASMX is simpler, and hosted on IIS, but harder to make cross platform capable.  WCF is more complex to configure and can be hosted by any .NET process. ADO.NET Data Services uses WCF.  WCF can be used to communicate between servers and applications.  &#8220;ABC&#8221;s of WCF: Address, Binding, Contract.  I think it&#8217;s time I learned about WCF&#8230;</p>
<p><strong>What&#8217;s New in the .NET 3.5 Framework for Web Developers and Intro to ASP.NET MVC - 10:40am</strong></p>
<p><a title="Dr. Z" href="http://blogs.msdn.com/zxue" target="_blank">Zhiming Xue</a>, Architect Evangelist.</p>
<p>New features introduced in .NET 3.5 SP1: ADO.NET Entity Framework, ASP.NET Dynamic Data, ADO.NET Data Services, ASP.NET Routing.</p>
<p><strong><em>ADO.NET Entity Framework</em></strong></p>
<p>Microsoft&#8217;s 1st ORM offering for .NET.  Designed for providing a UI for ORM development.</p>
<ul>
<li>Entity Data Modle (EDM) separates objects from their Data Structures.  Objects are mapped to their physical data store via three things: Conceptual Schema Definition (CSDL), Storage Schema Definition (SSDL), and the Mapping Specification (MSL).  This approach decouples the DB Schema from the Application Model.  This provides flexibility and can be platform independent (requires an Entity Data Provider.)</li>
<li>Entity Framework is a set of services that allow you to consume EDM from within your applications.  It includes Object Services, Entity Client, EntitySQL, and Linq-to-Entities.</li>
<li>Visual Studio Support is supposed to make the development seamless and simple.</li>
</ul>
<p>DataSets are raw data store connections.  Linq To SQL provides an ADO.NET connection to SqlServer.  Entity Framework is going to allow ORM connections to most any database.</p>
<p>DEMO: Z wrote live a WPF application that consumes EDM.  Create a WPF solution.  Add a DLL project and  add a new ADO.NET Entity Model item to the project.  Select the data connection and store it in the Web.config file.  The database is diagrammed in Visual Studio, complete with relationships.  It also creates a Mapping Details window, which he did not demonstrate, but it looks like that is where you change the mapping.  The EDMX file contains the XML definition of the SSDL and CSDL.  Copy the App.Config file from the EDM project to the WPF project - this links the WPF to the correct Data Store.  Add an xxxEntities model object to instantiate the connection.  Very fast development, very impressive results in less than 5 minutes!</p>
<p><strong><em>ASP.NET Dynamic Data</em></strong></p>
<p>Data driven web application scaffolding.  If you are unfamiliar, scaffolding, popularized by Ruby on Rails, provides default pages for Insert, Update, Delete, etc.  DD is based on an object model with full controls, metadata, validation, etc.  This is expressed in two new ASP.NET project types: Entity Data Model and Linq To SQL.</p>
<p>DEMO: Z added a Dynamic Data Web Application to the above demo so that he could tie in to the same EDM code he already produced.  Set the connection stream in the Web.config file to connect the site to the EDM data store.  Apparently DD is set up assuming Linq, so Z had to make changes to the Page Templates to use the EDM instead.  He had to change LinqDataSource to EntityDataSource.  Then he had to register the EDM assembly within the individual pages.  (Couldn&#8217;t you do this once in Web.config?)</p>
<p>The default scaffolding is very nice and has all the features you would expect.  I saw a Routing mechanism, but he did not really discuss how it is used.  He demonstrated custom validation. It uses <em>System.ComponentModel.DataAnnotations</em> and implements events for validation.</p>
<p>Overall it looks interesting, but I&#8217;m not sure yet how it would be used in a real world setting.</p>
<p><strong><em>ADO.NET Data Services</em></strong></p>
<p>Formerly &#8220;Astoria&#8221;, this technology exposes data in a secure fashion over the web or network.  It is a combination of patterns and libraries that enable the creation and consumption of data services for the web as &#8220;feeds&#8221;.  This does not have to be a database: it can be any data source.</p>
<ul>
<li>Implemented as ATOM - tables = feeds, rows = entities.  Includes CRUD, is RESTful, and a URI points to a resource.</li>
<li>Uses common URL syntax</li>
<li>Capable of exposing any object model that contains IQueryable&lt;T&gt;, such as Linq to SQL and EDM.</li>
<li>Locked down by default and supports Operation Batching</li>
<li>Supports optimistic concurrency</li>
</ul>
<p>DEMO: Z added a ADO.NET Data Service item to the above Web project.  You have to update the service code to indicate what the model is and set some rules.  It was a lot of copy and paste and went by too quickly to document.  At this point he basically lost me.  He hard coded the port the service executed on.  He generated a file using DataServiceUTIL.exe (but never executed the app that I saw) and then copied the file into the WPF solution.  He added a reference in the XAML to the service and a pointer to the service in App.config.  He did finally get it working, and it is interesting, but again I&#8217;m not sure how I would use it.</p>
<p><em><strong>ASP.NET Routing</strong></em></p>
<p>Routing maps an application URL to specific handlers.  I have been using this in ASP.NET MVC for a while, and they have always said that this was not limited to MVC.  His example used <em>DynamicDataRoute()</em> instances.  At this point his time was running short, so he didn&#8217;t really go into a lot of details.</p>
<p><em><strong>ASP.NET MVC</strong></em></p>
<p>As we know, MVC has been in my sights for a while now, and I have been very pleased with the implementation.  To be fair to Z, he was really rushing to get through this because of time.  Unfortunately, I think he skipped a lot of important basics, but he did at least demo the default and the Task List projects.  He really skimmed over the project types, and in the long run I think he just confused anyone who was not already familiar with MVC.  Last but not least, he only mentioned that you could use Unit Testing, but did not demo it at all.</p>
<p><strong>AJAX Development and Troubleshooting - 1pm<br />
</strong></p>
<p>Andrew Duthie presenting.  AJAX is a system of lightweight calls to the server without having to repost the entire web page.  I have used AJAX extensively in ASP.NET MVC using <a title="jQuery" href="http://www.jquery.com" target="_blank">jQuery</a>.</p>
<p><strong><em>ASP.NET AJAX</em></strong></p>
<ul>
<li>Simple Development Framework</li>
<li>Represented as additional libraries to ASP.NET</li>
<li>Two Models:</li>
<li>UpdatePanel Control (zero code implementation)</li>
<li>ScriptManager Control (provides a rich framework of JavaScript libraries)</li>
</ul>
<p>Included with .NET 3.5.  AJAX Control Toolkit is a separate project available from CodePlex.  The AJAX libraries work on Windows, Mac OS, and Linux in IE, Firefox, Opera, Safari, and others.</p>
<p>DEMO:  Andrew created an AutoComplete textbox sample. Create a Web Form and add an AJAX Form to it, which automatically set up the ScriptManager.  Add a reference to the AjaxControlToolkit.  Now all the Extenders are available in the toolbox.  Drag an AutoCompleteExtender to the page and set up a few attributes to hook into a data source.  Viola!  Good demo.</p>
<p>AJAX updates in .NET 3.5 SP1:</p>
<ul>
<li>Browser History - allows an Ajax page to be bookmarked for future return (including page data)</li>
<li>Script Combining - batches a set of Scripts to be treated as a single download</li>
</ul>
<p><span style="text-decoration: underline;"><strong>ANNOUNCEMENT</strong></span>: <a title="jQuery" href="http://www.jquery.com" target="_blank">jQuery</a> will be included in all future versions of Visual Studio!  It is to be treated as a first class citizen, complete with <a title="jQuery" href="http://www.jquery.com" target="_blank">jQuery</a> support.  Microsoft will even have full PSS support.  ASP.NET MVC will be the first ship of this feature.</p>
<p><strong>AJAX Troublesooting</strong></p>
<p>While it is a great tool, Visual Studio is not enough.  You also need tools for CSS, DOM, and Scripting analysis.</p>
<ul>
<li><a title="IE Developer Toolbar" href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fwww.microsoft.com%2Fdownloads%2Fdetails.aspx%3Ffamilyid%3De59c3964-672d-4511-bb3e-2d5e1db91038&amp;ei=MWTiSIqzJoLsgwTz-5WXDA&amp;usg=AFQjCNEFCIZRv-rL_JZ9pmEOWIrgTNCy8A&amp;sig2=VxKq_Xim12ua5rI_nftojQ" target="_blank">The IE Developer Toolbar</a> allows you to drill down into your code and is especially good for IE 6 and IE7.  IE8 has built in developer tools including JavaScript debugging, dynamic CSS changes, and more.</li>
<li><a title="Firebug" href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=https%3A%2F%2Faddons.mozilla.org%2Fen-US%2Ffirefox%2Faddon%2F1843&amp;ei=82PiSKHRA6SwgASDuIGQDA&amp;usg=AFQjCNGLyYT6w3IRt0w4Rt0DCyF1vfbgRA&amp;sig2=imqJYJ2Y5LVrIktdh3qK7g" target="_blank">Firebug</a> is a similar tool for Firefox.</li>
<li><a title="Firebug Lite" href="http://getfirebug.com/lite.html" target="_blank">Firebug Lite</a> is a tool that can be run without being installed (runs as a JavaScript app.)</li>
<li><a title="httpwatch" href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fwww.httpwatch.com%2F&amp;ei=sGTiSK-uMJ7MgQTq3rWODA&amp;usg=AFQjCNE9KsYnLY8TMWddUbyE-jSwWWxH8Q&amp;sig2=UpRC35joQi-oRREdM6C2HA" target="_blank">httpwatch</a> (IE and Firefox Only) - basic is free, pro costs money</li>
<li><a title="fiddler" href="http://www.fiddlertool.com/fiddler/" target="_blank">fiddler</a> - interaction record log</li>
</ul>
<p><em><strong>Other Frameworks</strong></em></p>
<ul>
<li><a title="The Dojo Toolkit" href="http://dojotoolkit.org/" target="_blank">The Dojo Toolkit</a></li>
<li><a title="Yahoo! UI" href="http://developer.yahoo.com/yui/" target="_blank">Yahoo! UI</a></li>
<li> <a title="jQuery" href="http://www.jquery.com" target="_blank">jQuery</a></li>
<li><a title="prototype" href="http://www.prototypejs.org/" target="_blank">prototype JavaScript Framework</a></li>
</ul>
<p>Andrew then spent the rest of the session showing some cool AJAX and JavaScript components.</p>
<p><strong>Microsoft Silverlight 2.0</strong></p>
<p>Ashish Jaiman, ISV Architect Evangelist</p>
<p>Silverlight is a cross browser, cross platform .NET plugin for delivering Rich Experiences in a browser.  Silverlight runs in the browser sandbox and executes .NET code.  Can be hosted in any container element in HTML.  HTML can be overlaid on top of Silverlight elements, and you can have many Silverlight components on a single page.</p>
<p>Silverlight 1.0 was only HTML and JavaScript.  Silverlight 2.0, on the other hand, includes a mini CLR, WPF controls, LINQ, collections, media, layout controls, and more.  Silverlight 2.0 has local storage, FileOpen capabilities, sockets, and cross domain HTTP requests.</p>
<p>Silverlight Pros:</p>
<ul>
<li>Video/Audio</li>
<li>Enhanced UX to increase stickiness</li>
<li>Decrease the learning curve</li>
<li>High resolution imagery</li>
<li>Data Visualization</li>
<li>Leverage .NET Skills for cross browser/cross platform solutions</li>
</ul>
<p>Silverlight Cons:</p>
<ul>
<li>Requires a browser plugin</li>
<li>There is still a learning curve</li>
<li>Need for designers to take full advantage</li>
</ul>
<p><strong>Designer and Developer Collaboration</strong></p>
<p>This brings up one of the main problems with WPF and Silverlight.  Microsoft&#8217;s belief is that developers should focus on developing data, communications, business rules, etc.  <em>Designers</em> should be the ones designing our user experiences.  As a one man shop, I can tell you that this isn&#8217;t going to happen, but I understand Microsoft&#8217;s point.</p>
<p>In order to really maximize the XAML abstraction concept, it will truly take a designer&#8217;s touch wrapped around a developer&#8217;s logic.  XAML is simply a description of a user interface in XML and contains no code.  A designer can then use tools like Expression Blend (2.5 for Silverlight 2.0) to design the interface, which will then export the design as XAML.  Visual Studio then can read the XAML and allow the developer to add any necessary application logic.  In fact, Blend and Visual Studio can be opened and used simultaneously against the same code, which is more realistic for someone in my shoes.</p>
<p>ASP.NET includes Silverlight support via the &lt;asp:xaml&gt; and &lt;asp:media&gt; tags, Silverlight has web-service support, and it can utilize the Membership, Profile, and Application Service integration.  IIS 7.0 also includes specific support for Silverlight.</p>
<p>Here is a pretty cool <a title="Silverlight demo" href="http://www.mscui.com/" target="_blank">Silverlight demo</a>.  (Go to the &#8220;Patient Journey Demonstrator&#8221;)</p>
<p>Styling and skinning are completely customizable, which is one of the main points of WPF technologies: however you can imagine visualizing your data or application, then you should be able to make it a reality in WPF/Silverlight.</p>
<p><em><strong>Local Storage</strong></em></p>
<p>&#8220;Cookies on steroids&#8221;, local storage provides 1MB of application specific local information.  Can be expanded if the user allows it.  Exposed through Microsoft Isolated Storage.</p>
<p><strong><em>DOM Integration</em></strong></p>
<p>Silverlight is still a browser application, so it can interact with and create HTML elements and scripts through .NET code.</p>
<p><em><strong>Open File Dialog</strong></em></p>
<p>You can use this to open a local file on the client.</p>
<p><em><strong>LINQ</strong></em></p>
<p>Silverlight 2.0 has LINQ support as part of its CLR.  Currently only on IEnumerable&lt;T&gt;, but XLINQ and DLINQ are in development.</p>
<p><em><strong>Data Acquisition</strong></em></p>
<p>Silverlight supports the following Methods:</p>
<ul>
<li>GET, POST,</li>
<li>Headers</li>
<li>Background threads</li>
<li>Streaming</li>
<li>Cross domain access (ClientAccess.xml, a subset of CrossDomain.xml)</li>
<li>WebClient and HttpWebRequest/Response</li>
</ul>
<p>The session ended when the instructor&#8217;s computer went belly up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/net/live-blogging-msdn-mid-atlantic-roadshow.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Authorize.Net Code Release</title>
		<link>http://www.developingfor.net/free-code/authorizenet-code-release.html</link>
		<comments>http://www.developingfor.net/free-code/authorizenet-code-release.html#comments</comments>
		<pubDate>Mon, 29 Sep 2008 22:16:39 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
		
		<category><![CDATA[.NET 3.5]]></category>

		<category><![CDATA[Free Code]]></category>

		<category><![CDATA[Miscellaneous]]></category>

		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=116</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/free-code/authorizenet-code-release.html";</script>var dzone_style="2";Back in February I posted the beginnings of a project to wrap Authorize.Net credit card transactions in C# .NET code.  I have been working on this project off and on, in conjunction with a new website we are developing, and have been meaning to post the production version for some time.
Today, I am [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/free-code/authorizenet-code-release.html";</script><script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>Back in February I posted the <a title="Authorize.Net" href="http://www.developingfor.net/miscellaneous/authorizenet-c-code.html" target="_self">beginnings of a project to wrap Authorize.Net</a> credit card transactions in C# .NET code.  I have been working on this project off and on, in conjunction with a new website we are developing, and have been meaning to post the production version for some time.</p>
<p>Today, I am publishing the current version of the code, <a title="Authorize.Net" href="DevelopingForDotNet.AuthorizeNet" target="_self">DevelopingForDotNet.AuthorizeNet</a>, along with a few supporting updates.  I&#8217;d like to thank everyone who posted comments on that entry and the <a title="First Foray into Unit Testing" href="http://www.developingfor.net/visual-studio/first-foray-into-unit-testing-with-visual-studio-2008.html" target="_self">First Foray into Unit Testing</a> entry.  Most of those suggestions made it into the final version and I learned a lot about Unit Testing along the way.</p>
<p>This version is slightly different than the original post.  Here are the major differences:</p>
<p><strong>Validity Checking</strong></p>
<p>This version incorporates validity checking on the following <em>TransactionRequest</em> class properties:</p>
<ul>
<li>EMail</li>
<li>Zip</li>
<li>SecurityCode</li>
<li>CardNumber</li>
<li>ExpDate</li>
</ul>
<p><em>EMail</em>, <em>CardNumber</em>, and <em>ExpDate</em> validation have been completely rewritten.</p>
<p><em>ExpDate</em> now accepts the following formats:</p>
<ul>
<li>MMYY</li>
<li>MM/YY</li>
<li>MM-YY</li>
<li>MMYYYY</li>
<li>MM/YYYY</li>
<li>MM-YYYY</li>
</ul>
<p>The Validity Checking uses a set of Regular Expression patterns that I have put into another namespace, <a title="Regex Support" href="http://www.developingfor.net/free-code/developingfordotnetregexsupport" target="_self">DevelopingForDotNet.RegexSupport</a>.  It will be available on the <a title="Free Code" href="http://www.developingfor.net/free-code" target="_self">Free Code</a> page as well.</p>
<p>Right now, all the failures throw an <em>ArgumentException</em>, which is very heavy handed but I haven&#8217;t had a need to improve it yet.</p>
<p><strong>INotifyPropertyChanged</strong></p>
<p>Each of the three classes implements <em>INotifyPropertyChanged</em> so you can use them for data binding if you wish.  If you have never implemented this interface before, it is very easy.  Add a reference to <em>System.ComponentModel</em> to your code. Then add the inheritance statement to your class:</p>
<div class="dean_ch" style="white-space: nowrap;">public class TransactionRequestInfo : INotifyPropertyChanged<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &#8230;<br />
<span class="br0">&#125;</span></div>
<p>Then implement the <em>PropertyChangedEventHandler</em> and add a method to fire the event:</p>
<div class="dean_ch" style="white-space: nowrap;">public event PropertyChangedEventHandler PropertyChanged;</p>
<p>protected <span class="kw4">void</span> OnPropertyChanged<span class="br0">&#40;</span><span class="kw4">string</span> propertyName<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>this.<span class="me1">PropertyChanged</span> != <span class="kw2">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; PropertyChanged<span class="br0">&#40;</span>this, new PropertyChangedEventArgs<span class="br0">&#40;</span>propertyName<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>Then call the method whenever a property changes:</p>
<div class="dean_ch" style="white-space: nowrap;">public <span class="kw4">string</span> FirstName<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> _first; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _first = value;<br />
&nbsp; &nbsp; &nbsp; &nbsp; OnPropertyChanged<span class="br0">&#40;</span><span class="st0">&quot;FirstName&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>Easy as can be!</p>
<p><strong>Transaction.ProcessPayment</strong></p>
<p><em>Transaction</em> is a static class with <em>ProcessPayment</em> as its single static method.  In reviewing the project, I realized that this was a perfect case for an Extension Method, so I added <em>this</em> before the first keyword, and now calling the method is even nicer than before:</p>
<div class="dean_ch" style="white-space: nowrap;"><span class="co1">// Account is built above&#8230;</span><br />
TransactionResponseInfo pmtResponse = pmtInfo.<span class="me1">ProcessPayment</span><span class="br0">&#40;</span>Account<span class="br0">&#41;</span>;</div>
<p><strong>Unit Testing</strong></p>
<p>I really got my feet wet with Unit Testing on this project.  I followed the <a title="Freekshow - Unit Testing" href="http://freekleemhuis.wordpress.com/2008/06/26/unit-testing-with-visual-studio-2008-part-2/" target="_blank">advice I got from FreekShow</a> and implemented the testing of Exceptions in a much cleaner fashion.  The whole experience got me thinking about why Unit Testing is so beneficial, and as I began rewriting the code I started by writing tests that fail first and then coding my way into success.  Just for grins, the testing project for this solution is included in the download.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/free-code/authorizenet-code-release.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Extensions update and new Namespace added to Free Code</title>
		<link>http://www.developingfor.net/free-code/extensions-update-and-new-namespace-added-to-free-code.html</link>
		<comments>http://www.developingfor.net/free-code/extensions-update-and-new-namespace-added-to-free-code.html#comments</comments>
		<pubDate>Mon, 29 Sep 2008 21:59:23 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
		
		<category><![CDATA[.NET 3.5]]></category>

		<category><![CDATA[Free Code]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=122</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/free-code/extensions-update-and-new-namespace-added-to-free-code.html";</script>var dzone_style="2";In support of the Authorize.Net project, I have updated the Free Code page:

DevelopingForDotNet.Extensions - updated with many new Extension Methods.
DevelopingForDotNet.RegexSupport - contains a list of useful Regular Expression Patterns.

]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/free-code/extensions-update-and-new-namespace-added-to-free-code.html";</script><script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>In support of the Authorize.Net project, I have updated the <a title="Free Code" href="http://www.developingfor.net/free-code" target="_self">Free Code</a> page:</p>
<ul>
<li><a title="Extension Methods" href="http://www.developingfor.net/free-code/developingfordotnetextensions" target="_self">DevelopingForDotNet.Extensions</a> - updated with many new Extension Methods.</li>
<li><a title="Regex Support" href="http://www.developingfor.net/free-code/developingfordotnetregexsupport" target="_self">DevelopingForDotNet.RegexSupport</a> - contains a list of useful Regular Expression Patterns.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/free-code/extensions-update-and-new-namespace-added-to-free-code.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>ASP.NET MVC 5 Update</title>
		<link>http://www.developingfor.net/aspnet-mvc/aspnet-mvc-5-update.html</link>
		<comments>http://www.developingfor.net/aspnet-mvc/aspnet-mvc-5-update.html#comments</comments>
		<pubDate>Wed, 24 Sep 2008 21:20:26 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
		
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=108</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/aspnet-mvc/aspnet-mvc-5-update.html";</script>var dzone_style="2";Yesterday I wrote about updating to ASP.NET MVC Preview 5.  Today I tested the changes I made and they failed, so I obviously had a little more work to do.
First, I had to update the Web.config file in several places (just like I did going from Preview 2 to Preview 3.)  The [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/aspnet-mvc/aspnet-mvc-5-update.html";</script><script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>Yesterday I wrote about updating to ASP.NET MVC Preview 5.  Today I tested the changes I made and they failed, so I obviously had a little more work to do.</p>
<p>First, I had to update the Web.config file in several places (just like I did <a title="Going from Preview 2 to Preview 3" href="http://www.developingfor.net/aspnet-mvc/updating-from-aspnet-mvc-preview-2-to-preview-3.html" target="_self">going from Preview 2 to Preview 3</a>.)  The only way I could get this to work was to create a brand new Preview 5 web page project and copy the afflicted lines from the new Web.config to the old one.  I also went ahead and updated the <em>namespaces</em>, <em>httpModules</em>, and <em>httpHandlers</em> sections.</p>
<p>Then, with the site actually running again, I tried a full blown walk through and discovered a problem.  Since <em>System.Web.Mvc.BindingHelperExtensions </em>was replaced with a call to <em>UpdateModel(</em><em>model, Request.Form.AllKeys</em><em>)</em>, an error occurred.  Specifically, a <em>NullReferenceException</em> was thrown because &#8220;AllKeys&#8221; contained form elements that are not properties in the model object.  My gut reaction was to simply add them to my class, but that just didn&#8217;t seem right: the model should be unaffected the presentation.</p>
<p>So, at least as a temporary solution, I created a custom <em>List&lt;string&gt;</em> of Keys. I used Reflection to get a list of Property names, and if those names are in <em>Requst.Form.AllKeys</em> then I add it to my list:</p>
<div class="dean_ch" style="white-space: nowrap;">typeof<span class="br0">&#40;</span>TransactionRequestInfo<span class="br0">&#41;</span>.<span class="me1">GetProperties</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">ToList</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">ForEach</span><span class="br0">&#40;</span>p =&gt;<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>Request.<span class="me1">Form</span>.<span class="me1">AllKeys</span>.<span class="me1">Contains</span><span class="br0">&#40;</span>p.<span class="me1">Name</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; keys.<span class="me1">Add</span><span class="br0">&#40;</span>p.<span class="me1">Name</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</p>
<p>UpdateModel<span class="br0">&#40;</span>pmtInfo, keys.<span class="me1">ToArray</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
<p>{<strong>NOTE: </strong>TransactionRequestInfo and pmtInfo are from the Authorize.Net project, which I still need to update on the site.}</p>
<p>After I got it working, I realized that this is actually a query, so I could use Linq instead:</p>
<div class="dean_ch" style="white-space: nowrap;">var keys = from p in typeof<span class="br0">&#40;</span>TransactionRequestInfo<span class="br0">&#41;</span>.<span class="me1">GetProperties</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where Request.<span class="me1">Form</span>.<span class="me1">AllKeys</span>.<span class="me1">Contains</span><span class="br0">&#40;</span>p.<span class="me1">Name</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;select p.<span class="me1">Name</span>;<br />
UpdateModel<span class="br0">&#40;</span>pmtInfo, keys.<span class="me1">ToArray</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
<p>This shortened the code, got rid of a Lambda Expression, and prevented the need to cast the <em>Properties[]</em> to a<em> List&lt;PropertyInfo&gt;</em> object.</p>
<p>I should probably add logic to make sure only Public properties are selected.  Since I may end up using this in more than one place, I will probably want to make it an Extension method of Request.Form.</p>
<p><strong>One more problem</strong></p>
<p>After updating my assembly references in Web.config and reloading the site, I received an error because it could no longer find the referenced assembly.  I checked in my bin folder and sure enough the assemblies were not there.  Compiling the solution did not replace them as it had before, so I copied them into bin from the <em>C:\Program Files\Microsoft ASP.NET\ASP.NET MVC CodePlex Preview 5</em> directory and reloaded the site.  Once again, all is working properly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/aspnet-mvc/aspnet-mvc-5-update.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Updating to ASP.NET MVC Preview 5</title>
		<link>http://www.developingfor.net/aspnet-mvc/updating-to-aspnet-mvc-preview-5.html</link>
		<comments>http://www.developingfor.net/aspnet-mvc/updating-to-aspnet-mvc-preview-5.html#comments</comments>
		<pubDate>Tue, 23 Sep 2008 21:02:28 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
		
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://www.developingfor.net/?p=105</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/aspnet-mvc/updating-to-aspnet-mvc-preview-5.html";</script>var dzone_style="2";Well, I once again fell off the wagon when it comes to updating this site.  I&#8217;ve been so busy working on my new ASP.NET MVC project that I even missed the Preview 4 update.  That would be bad enough, until I recently found out that Preview 5 is now out.  What [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.developingfor.net/aspnet-mvc/updating-to-aspnet-mvc-preview-5.html";</script><script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>Well, I once again fell off the wagon when it comes to updating this site.  I&#8217;ve been so busy working on my new ASP.NET MVC project that I even missed the Preview 4 update.  That would be bad enough, until I recently found out that <a title="ASP.NET MVC 5 CodePlex" href="http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16775" target="_blank">Preview 5</a> is now out.  What a slacker I am!</p>
<p>So I spent the last little bit updating my Preview 3 projects to Preview 5.  I don&#8217;t know how much of this was Preview 4 specific since I skipped it entirely.  Here is what I did:</p>
<ol>
<li>Uninstall Preview 3 from my PC.</li>
<li>Close all Visual Studio instances.</li>
<li>Install Preview 5.</li>
<li>Open my MVC projects.</li>
<li>Remove previous references to <em>System.Web.Abstractions, System.Web.Mvc, </em>and <em>System.Web.Routing</em>.</li>
<li>Add these references back, pointing now to the new install path.</li>
<li>Add a reference to <em>Microsoft.Web.Mvc</em>, found in the same location.</li>
</ol>
<p><strong>Breaking Changes</strong></p>
<p>I had used <em>System.Web.Mvc.BindingHelperExtensions</em> in several locations, but this functionality has been moved to the Controller class.  To correct it, simply replace the calls to <em>BindingHelperExtensions.UpdateFrom(model, Request.Form)</em> with <em>UpdateModel(model, Request.Form.AllKeys)</em>.</p>
<p>That was all I had to do to get it up and running.  Now I need to uninstall Preview 3 from the server, install Preview 5, and reload my sites.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingfor.net/aspnet-mvc/updating-to-aspnet-mvc-preview-5.html/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
