Fluff

How I Got Started in Programming

Lots of people around the web have done this one and who am I to break the trend? 😉

How old were you when you started programming?
I wrote a little about my journey to becoming a coder here. Basically, I was very very young. I used to program BASIC by copying the programs out of GAMES magazine and getting them to work. I also used to write programs to simulate computer systems like what you’d see in Wargames, for instance.

What was your first language?
I Speak Basic to my Commodore 64Kind of mentioned it above, but BASIC on my Commodore 64. In fact, my first book on programming was called “I Speak BASIC to my Commodore 64”.

What was the first real program you wrote?
What qualifies as a “real program”? I wrote programs in school on the Tandy for projects and on Apple IIe in high school. I wrote a secret message sending program in VB6. The first thing I was paid to write was in Access. It kept track of credit limits of commercial customers for a large bank’s commercial vault network.

What languages have you used since you started programming?
BASIC, VB6, VBScript, VBA, VB.Net (a theme?), C#, T-SQL, C++, Javscript, and PHP.

I have fooled around with (meaning worked through tutorials on) Ruby, F#, Python, and Perl.

What was your first professional programming gig?
As I mentioned above, I worked for a very large bank in their commercial vault division. Basically, customers ordered large amounts of money from the vaults and the money would actually leave the vault via armored cars before the money would be withdrawn from their accounts, leading to a liability. Underwriters determined the amount of exposure that the bank was willing to risk with each customer. My shared Access database program had forms for entering and reporting on all of the information, as well as pulling down data from the Informix system that housed the orders so that we had current information about the state of things. Woo-hoo.

If you knew then what you know now, would you have started programming?
Oh, yeah. I would have gone hardcore earlier and stopped that BASIC trail I was blazing and switched to other languages that would have caused me to learn more about the art of programming.

If there is one thing you learned along the way that you would tell new developers, what would it be?
Seriously, you don’t know as much as you think you do. I understand… I’ve been there. But just because you wrote some app that organizes your MP3 collection, you don’t know that much about programming. You can’t learn programming by sitting in a class and you can’t learn solely by reading books. The books help, for sure, but only by writing code, reading code, and interacting with other coders can you really learn. Trust me, the more you know, the more you’ll realize you don’t know.

Don’t stop learning ever. Technology is always changing and you will be “the new guy” in some piece of the game all the time. Don’t forget that and never be too proud to ask for help. The community by and large loves to share its knowledge. Listen to podcasts, participate in forums, read blogs, and go to conferences and user groups. You can thank me later.

What’s the most fun you’ve ever had … programming?
Every time that I’ve had to do crazy things or solve problems that were really difficult. One that comes to mind was a time that Jeff and I had to work late to work out an interoperability problem between our company’s web service and another company’s web service (the night he literally saved my life). We were using security and encrypting the payload, etc, but we had to pore over these boring OASIS specifications (but what about OASIS?!?!?) in order to figure out exactly why the messages weren’t being accepted. Annoying at the time, but so much fun working out the old grey matter and so rewarding when we succeeded. And, to top it off, I know way more about that topic than I ever would have otherwise.

Podcasts

My Favorite Programmer Podcasts

Road Image From http://www.sxc.hu/photo/973008I use to have an hour long commute to work. It has been reduced to 35 minutes now with my new position, but I still have 5 hours a week where I’m not being at all productive. I used to listen to books on CD to pass the time, but what I really wanted to do was learn more about programming!

Since Code Complete isn’t out as an audio book yet, I had to turn to podcasts. At the time, I still had 10 hours of drive time, so I was really burning through them. At first, all I had was my nerd-crush Scott Hanselman’s podcast “Hanselminutes”. However, I blew through the archive in a hurry and I needed more.

I had a really hard time finding good podcasts that were updated fairly regularly and that talked about the kinds of things that I wanted to learn about. Since that time, I’ve built up a nice little rotation and I thought that I would share my favorites with you. I wish I could have found a list like this when I was searching, so maybe I can be a help to someone else who is starting out.

Here is my list. In order of preference. I don’t waffle and I calls ’em likes I sees ’em.

Hanselminutes RSS Feed
My absolute favorite podcast. When I discovered this, I liked it so much that I went back and listened to every single episode. When a new one comes out, I bump it to the top of the playlist and hear it next. Worth a listen for the theme music alone ;). Description from the site: Hanselminutes is a weekly audio talk show with noted web developer and technologist Scott Hanselman and hosted by Carl Franklin. Scott discusses utilities and tools, gives practical how-to advice, and discusses ASP.NET or Windows issues and workarounds.
StackOverflow Podcast RSS Feed
This is the podcast to discuss Jeff Atwood and Joel Spolsky’s joint business venture of StackOverflow.com. Well, that is what it is intended to do. In reality, they talk about a lot of issues that are tangential to Jeff’s work or things that have annoyed either one of them in the past week. They also take user questions.
Polymorphic Podcast RSS Feed
This podcast isn’t updated as frequently, but I still like to listen to it when it is new. The tagline is “Object Oriented Development, Architecture, and Best Practices in .Net” and that about sums up what the show is about. Craig Shoemaker, the host, also does webcasts over at getpixel8ed.com. A bit of trivia: I won an ASP.Net Infragistics Controls license for answering a trivia question posed on this podcast!
Deep Fried Bytes RSS Feed
Deep Fried Bytes is a new podcast with Keith Elder and Chris Woodruff. It is described as “The show discusses a wide range of topics including application development, operating systems and technology in general”. Some great recent shows have covered .Net development on a Mac and scaling large websites.
.Net Rocks RSS Feed
.Net Rocks. If you don’t know about this one, you’ve been hiding. Carl Franklin and Richard Campbell do an hourlong show and discuss all sorts of topics in the Microsoft world.
Google Developer Podcast RSS Feed
This podcast isn’t updated very frequently at all. It isn’t boring and does let you know what Google is up to for developers, but I use it as “filler” if I’m all caught up on other podcasts and I need something to listen to on the commute.
Alt.Net Podcast RSS Feed
If you haven’t heard of Alt.Net, it is a group of developers who develop using .Net technologies, but they like to have some choice in how they do things, borrowing heavily from what other development communities are doing. This podcast has a lot of information, but is really dry and another one that I use for filler.

I have a few more that I dig deep on if I am totally out of stuff, but by that time, my regulars have churned out some new podcasts and I don’t need to go much further. If you have one that you really enjoy, leave it as feedback in the comments, I’d love to check it out.

Rant

Sql Reference Tables

Reference Book Image from http://www.sxc.hu/photo/1022436
Disclaimer: Personally, I prefer to use uniqueidentifier as my primary key data type. It cuts down on improper joins (similar looking values aren’t in every table, ie 1, 2, 3) and is infinitely portable among environments. I think the extra space and overhead is worth it.

We have some reference tables in our database at work. This itself isn’t abnormal, everyone has these. What made these tables special was that the IDENTITY Primary Key for the table started at 0. At first I thought that this was awesome. I know it is a debate for another day, but I love that my arrays, counters, etc start at 0 in C#. I know it may not be necessary anymore or whatever, but it comforts me, okay? 🙂

Things soon changed for the worse when I realized that 0 being a significant data value was a problem. “Why?”, you may ask. Well, when you just generically “new up” an int, what is the default value? That’s right, 0. So, if someone doesn’t set a property when trying to identify some reference value, in a 1-based table (or a GUID one) you will get an error because that isn’t a valid value. However, in a 0-based table, that “forgetfulness” will match right up with a value and go in no questions asked. You can’t validate it, because 0 is perfectly fine to have.

Lesson Learned: Zeroes are fine for arrays and loops, but keep them out of reference tables!

Code Tips

Web Services Software Factory (5 of 5)

Note: All links current as of the time of this blog post

We have landed. This is tutorial part 5 of 5. In parts 1-4 (part 1 starts here) we created a web service that does some simple encryption, decryption, and hashing. Before beginning this part of the tutorial, please create a virtual directory in IIS pointing to the Web Service project that you set up in part 4 and make it a .Net application. I named the virtual directory CryptService and as such I can browse to http://localhost/CryptService/CryptService.svc and see the service.

Create a new C# Console Application. I named my application TestCryptService. Right click on your project in solution explorer and select “Add Service Reference”. Put your URL to your service in and click Go. After a few moments, you should see what was discovered about your service. Change the namespace to CryptService and click Ok.
Add Service Reference to Project

Notice that all of the binding information has been added to your app.config. If you look at the endpoint section, you will see that /basic was added to the end of the CryptService.svc. I mentioned last time that that allows you to create multiple endpoints to the same point, and just use different bindings, etc.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="Crypt" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost/CryptService/CryptService.svc/basic"
                binding="basicHttpBinding" bindingConfiguration="Crypt" contract="CryptService.CryptService"
                name="Crypt" />
        </client>
    </system.serviceModel>
</configuration>

Now, within the Program.cs file that was created for you, enter in this code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TestCryptService.CryptService;

namespace TestCryptService
{
    class Program
    {
        static void Main(string[] args)
        {
            TestDesEncryption();
            TestRijndaelEncryption();
            TestMd5Hash();
            TestSha256Hash();
        }

        /// <summary>
        /// This method is the only one that is commented.  All of the other methods function 
        /// in exactly the same way.  The only reason they are included is for completeness, 
        /// so that all of our server methods are hit.
        /// </summary>
        static void TestDesEncryption()
        {
            // The CryptServiceClient is the proxy created automatically for you.
            // It would be called CryptServiceClient whether you used svcutil.exe 
            // yourself or you added a service reference.
            CryptServiceClient client = new CryptServiceClient();
            

            EncryptionObject encryptionObject = new EncryptionObject();

            encryptionObject.EncryptionAlgorithm = EncryptionAlgorithm.DES;
            encryptionObject.Text = "Testing our DES Encryption";

            // Call the EncryptString method and get back our encrypted value
            string encryptedText = client.EncryptString(encryptionObject);

            encryptionObject = new EncryptionObject();
            encryptionObject.EncryptionAlgorithm = EncryptionAlgorithm.DES;
            encryptionObject.Text = encryptedText;

            // Call the DecryptString method and get back our plain text
            string plainText = client.DecryptString(encryptionObject);

            // Output the values and see what we get.
            Console.WriteLine("-- DES --");
            Console.WriteLine("Encrypted Text: {0}", encryptedText);
            Console.WriteLine("Plain Text: {0}", plainText);
            Console.WriteLine();
        }

        static void TestRijndaelEncryption()
        {
            CryptServiceClient client = new CryptServiceClient();
            EncryptionObject encryptionObject = new EncryptionObject();

            encryptionObject.EncryptionAlgorithm = EncryptionAlgorithm.Rijndael;
            encryptionObject.Text = "Testing our Rijndael Encryption";

            string encryptedText = client.EncryptString(encryptionObject);

            encryptionObject = new EncryptionObject();
            encryptionObject.EncryptionAlgorithm = EncryptionAlgorithm.Rijndael;
            encryptionObject.Text = encryptedText;

            string plainText = client.DecryptString(encryptionObject);

            Console.WriteLine("-- Rijndael --");
            Console.WriteLine("Encrypted Text: {0}", encryptedText);
            Console.WriteLine("Plain Text: {0}", plainText);
            Console.WriteLine();
        }

        static void TestMd5Hash()
        {
            CryptServiceClient client = new CryptServiceClient();
            HashObject hashObject = new HashObject();

            hashObject.HashType = HashType.MD5;
            hashObject.StringToHash = "Some string to hash";

            string md5Hash = client.HashString(hashObject);

            Console.WriteLine("-- MD5 Hash --");
            Console.WriteLine("Original String: {0}", hashObject.StringToHash);
            Console.WriteLine("Hashed Value: {0}", md5Hash);
            Console.WriteLine();
        }

        static void TestSha256Hash()
        {
            CryptServiceClient client = new CryptServiceClient();
            HashObject hashObject = new HashObject();

            hashObject.HashType = HashType.SHA256;
            hashObject.StringToHash = "Some string to hash";

            string shaHash = client.HashString(hashObject);

            Console.WriteLine("-- Sha256 Hash --");
            Console.WriteLine("Original String: {0}", hashObject.StringToHash);
            Console.WriteLine("Hashed Value: {0}", shaHash);
            Console.WriteLine();
        }
    }
}

When I run this code, I see this output:
Test Console Output

That is IT! If you’ve made it this far and see that output, you are done. You are now ready to use the Web Services Software Factory to make web services yourself. As always, if you didn’t get these results, double check your steps and if you are still having problems, leave me a comment and I will try to help you.

All code was written as throwaway code, so I realize that it could use some refactoring and some optimization. The point of this tutorial was to expose you to using the WSSF in more than a “Hello World” kind of way and to at least mimic the real world with something a little bit fun.

Code Tips

Web Services Software Factory (4 of 5)

Note: All links current as of the time of this blog post

We are in the home stretch. If you haven’t already, you may want to take a look at tutorial parts 1, 2, and 3 before beginning this one.

At this point, we’ve defined our service, created Data Contracts and Service Contracts, implemented the serivce, and programmed the code behind the endpoints. All we have left to do before this service is fully functional is to create the Host Contracts, which will set up the actual endpoints for us.

In your Solution Explorer, right click on the MyCryptographyService.model and choose Add –> New Model. In the dialog, select Host Model and complete the the form and click finish.
New Host Contract Model Dialog

This brings up a new designer surface for the Host Designer.
Host Model Designer

The very first thing we need to do is to right click on the Host Model in the Host Explorer and select “Add New Host Application”.
Add New Host Application Menu

This will create HostApplication1. Right click on it and view properties. Change the name to “CryptographyServiceWS” and the Implementation Technology to “WCF Extensions”. For Implementation Project you need to pick the project that is going to be the one the people will actually connect to. You can create your own Web Services project if you’d like, but there is one already included for us, so I will use that one for the purposes of this experience. Expand the dropdown as shown below and choose MyCrytographyService.Host.
Choose a Host Project

Return to the Host Explorer, right click on CryptographyServiceWS and choose “Add New Service Reference”. This creates ServiceReference1.
Add Service Reference to Host

Right click on ServiceReference1, choose properties and set its name to CryptService. Select to Enable Metadata Publishing to true. For Service Implementation Type, click the ellipses to bring up this dialog and choose CryptService.
DSL Model Element Selector

Go back to the Host Explorer. Right click on CryptService and choose “Add New Endpoint”. Endpont1 will appear. Right click on Endpoint1, select properties and change its name to Crypt, leave Binding Type at basicHttpBinding, and enter “Basic” in the Address field. As the tooltip says, the Address field allows you to append something to the name of the endpoint so that you can create many different endpoints, each to the same code. The point being to allow users to connect with many different bindings, but to do that you must create an endpoint for each. Rather than have many different endpoint names, you can just add a suffix. Additionally, this can also be used to version the endpoints on your service.

That’s it. When you click again on CryptService in the Host Explorer, you see this screen on the left. Click “Generate Service” and if you’ve done everything correctly, you should be set to go. If you do not see this screen, that means you have left out a step. Please review the tutorial up to this point and if you are still stuck, leave me a comment and I will try to help.
Auto Generate Service

Now, if you go back to your Solution Explorer and navigate to the Tests folder and look inside the MyCryptographyService.Hosts project, you will see the CryptService.svc file.
CryptService.svc

This is the “page” that people will connect to. In fact, if you right click on it and choose “View in Browser” you should see the page below.
CryptService Page in Browser

If you click the link that is provided on that page, you can see the WSDL from the service itself.
CryptService WSDL

That’s it. Your WCF service is now fully functional. In the final piece of the tutorial, we’ll make a C# Console Application that calls our service and gives us back some results.