Kevin Isom

Just a good ol' boy, by-God Virginia-proud and country-sophisticated -- sort of like a John Deere tractor with air conditioning and satellite radio.

  • Generating Images With .Net Part 1

    I’ve recently had a project that required a great deal of image generation and manipulation. Not having done image manipulation in a good long while I thought it would be good to capture some of the “tricks of the trade”. One of the things I noticed in my searching for information on generating images in .Net is how bad variables were named. Hungarian notation or single letter names. This is not cool so I’m going to be trying to use descriptive names for all of my variables.

    Read more...

  • REST as Simple as Possible

    I've been doing a lot of REST based services lately and for something that is as simple a concept as REST it is actually not the easiest thing to find guidance for a .Net developer. It's simple, or at least it should be. My first stop was the WCF Rest Starter Kit. I thought great, surely this would get me going with no fuss. I only wish it were so. I thought I could create a project with it and just get going. Instead what I got was a whole heap of code that didn't really start me on the way at all. I won't totally bag on the starter kit. I rather like the items around the atom publishing protocol. I briefly considered just writing an http handler for that but I knew that there had to be a better way.

    Enter WCF.

    It is actually incredibly easy to write REST services in .net. with WCF. 

    Step 1

    Create a new WCF service  in your website.

    Step 2

    Go to the cruft VS adds to your Web.config when creating your service and remove it and replace it with the following

       1:  <system.serviceModel>
       2:      <behaviors>
       3:          <endpointBehaviors>
       4:              <behavior name="web">
       5:                  <webHttp/>
       6:              </behavior>
       7:          </endpointBehaviors>
       8:      </behaviors>
       9:      <services>
      10:          <service name="Service">
      11:              <endpoint address=""
      12:                    binding="webHttpBinding"
      13:                    contract="IService"
      14:                    behaviorConfiguration="web"/>
      15:      </service>
      16:      <service name="WebsiteService">
      17:          <endpoint address=""
      18:                   binding="webHttpBinding"
      19:                   contract="WebsiteService"
      20:                   behaviorConfiguration="web"/>
      21:          </service>
      22:      </services>
      23:  </system.serviceModel>


    And all you have to do it is add some attributes to your service contract

       1:  using System.ServiceModel;
       2:  using System.ServiceModel.Web;
       3:   
       4:  [ServiceContract]
       5:  public interface IService
       6:  {
       7:      [OperationContract]
       8:      [WebGet(UriTemplate = "/SayHello", ResponseFormat = WebMessageFormat.Xml)]
       9:      string SayHello();
      10:   
      11:      [OperationContract]
      12:      [WebGet(UriTemplate = "/SayHello/{user}", ResponseFormat = WebMessageFormat.Xml)]
      13:      string SayHelloToUser(string user);
      14:   
      15:      [OperationContract]
      16:      [WebGet(UriTemplate = "/SayHelloInJson/{user}", ResponseFormat = WebMessageFormat.Json)]
      17:      string SayHelloToUserInJson(string user);
      18:   
      19:      [OperationContract]
      20:      [WebGet(UriTemplate = "/GetPackage", ResponseFormat = WebMessageFormat.Json)]
      21:      Package GetPackage();
      22:   
      23:   
      24:      [OperationContract]
      25:      [WebInvoke(Method = "POST", UriTemplate = "/PlainPost", ResponseFormat = WebMessageFormat.Xml,
      26:          BodyStyle = WebMessageBodyStyle.Wrapped)]
      27:      int PlainPost(string username, string name, string message);
      28:   
      29:  }

    Then implement the interface and you are good to go. I'll cover consuming these with both .Net and Javascript in a later post.

    The attributes are where the real magic happens

    The WebGet attribute tells WCF that this method is invoked via an HTTP Get Request.

    The UriTemplate attribute property sets the URI of the call so on SayHello the url requested would be ~/Service.svc/SayHello

    The ResponseFormat attribute property tells the service to return either XML or Json depending on the value of the WebMessageFormat enum

    The WebInvoke attribute gives you to specify the type of HTTP request you make. The default method is POST.

    The BodyStyle attribute property sets the body style of the messages sent to and from the service.

    There you have it. Simple REST from WCF.

    Cheers

    Read more...

  • Testing Web Services remotely

    I hate it when I forget something. I had one of the guys on my team today asked me how to invoke a web service remotely as he was getting an error. Well I knew right away what the problem was. But could remember the solution so I had to look and now I'm gonna put it here so it'll be easier to find next time.

    Read more...

  • Web Development with Internet Explorer

    Firebug rocks. Nothing, I mean nothing beats it for debug web pages. But what do you do for problems specific to IE (most notably IE 6) Here are a list of tools I use to help cause telling the user to get a real browser is not a solution

    Read more...

  • Visual Basic.Net and NUnit Gotcha

    I like the NUnit 2.4 Constraint based syntax. So In my new role I am having to implement Unit Testing so I decided on going with NUnit to begin with despite my preference for MbUnit. But once I got started writing my tests, I discover Is is a keyword in VB (I'm more of a C# person, but hey I'm no language bigot). I kinda freak out a little. Did I do something wrong? Forget to add something? Google a bit and still no joy. Then I remember the code examples installed with NUnit and have a look and what do you know? Is is now Iz in VB. Not exactly as clear as Is but you gotta do what you gotta do. So now in VB a Unit Test looks like this

    Read more...

  • Web Application Projects and Profiles

    So, I'm working on a Web Application Project in Visual Studio 2008 and I realize I don't have a strongly typed Profile object...So I Google around and find that this a Problem in Visual Studio 2005 and that Microsoft didn't fix the problem in VS 2008. Needless to say I was a little unimpressed. But I also found the Web Profile Builder at the MSDN Code Gallery. I followed the instructions here and was away running.

    Read more...