SourceSafe + Web Projects = Oil + Water


Okay, I know I am bitching right now, but the dumbing down of development has reached a point where so many of the tools we have relied on in the past (yes, I am talking about SourceSafe … favorably, for a change) do not work correctly. As we dumb things down, the scenarios that are tested get reduced to the dumbed down set to the exclusion of the more professional set of functions.

Now that I have some of you asking "was that English?", let me explain. While SourceSafe is an inferior source control system (compared to more Enterprise strength products), it is a reality for many of us. And, although we complain from time to time, it works. In Visual Studio 2003, with SourceSafe 6.0d, the largest headache was setting up the project on machines (get source, make a web project, etc.). This portion has been greatly simplified in Visual Studio 2005 as you can now leave the website as a file based web.

Now for the pain. As long as you keep everything in the App_Code folder and rely on NO external assemblies (ie, you code wrong for the Enterprise), you are fine. If you include other files, you are screwed. Want to test this. Follow these steps:

  1. Create a library (or use one you already have). If you are creating, just add a simple class that returns Hello World when you call a method. This is your external library.
  2. Check librar into sourcesafe
  3. Create a new website (file-based or IIS)
  4. Add reference to the library
  5. Check into sourcesafe
  6. Go to another machine (or a virtual instance).
  7. Get code from sourcesafe on this machine
  8. Compile. Woo Hoo! So far so good.
  9. Change the class library by adding additional methods
  10. Check in
  11. Use these additional methods in your web library
  12. Go to other machine and get latest
  13. Run project! BOOM!

To fix this issue, you have to re-reference the DLLs in the machine where things are blowing up by using Add Reference. And, you have to do this on EVERY machine that you are using it.

This is an issue with the project-less model of ASP.NET 2.0 and does not affect people who compile all of their tiers into their web apps. For those of us who have tiered apps (mandatory in Enterprise systems), the dumbing down of the web has its downside.

Advertisements

SOA for the Masses


I just received an invitation to review a proposal for a book on SOA. The first question, as always is "do you think this book is necessary?" Well, not only yes, but hell yes. But, I digress.

SOA for the Masses

First, let’s understand what SOA is. In simple terms, SOA is two things:

  1. Boxing up a set of functions into a service (a complete piece of software that performs a narrowly focused set of functions). In general, you aim for something specific, like a security service, a zipcode lookup service, etc.
  2. Putting an interface to reach the service over the wire. In general, you will want this to be a standards based interface, like web services, but any interface you can agree on is still SOA.

Yes, I have just exposed the man behind the curtain. You are probably thinking it cannot be that simple, can it. Let me show you how simple it is.

Step 1: Create a web page

In this case, I am aiming for simplicity. Open Visual Studio 2005 and create a new web site. In the default.aspx page, add two textboxes, with a plus sign in between, a horizontal line and a label and button. The code will be something like this:

<div>
<asp:TextBox ID="TextBox1" runat="server" Width="67px"></asp:TextBox
>
+
<asp:TextBox ID="TextBox2" runat="server" Width="67px"></asp:TextBox><br
/>
____________________<br
/>
= <asp:Label ID="Label1" runat="server"></asp:Label><br
/>
<asp:Button ID="Button1" runat="server" Text="Button"
/>
</div>
 

Double click on the Button and add the followign coded method.

VB.NET

Protected Sub Button1_Click(ByVal sender As Object, _
            
ByVal e As System.EventArgs) Handles Button1.Click
    Label1.Text = VBCalculator.Add(_
       Integer.Parse(TextBox1.Text), Integer.Parse(_
       TextBox2.Text)).ToString()
End Sub

C#

protected void Button1_Click(object sender, EventArgs e)
{
    Label1.Text = CSharpCalculator.Add(
int.Parse(TextBox1.Text),
             
int.Parse(TextBox2.Text)).ToString();
}

Now, you need to add the calculator class(es). In this case, we are simply adding two integers. Yeah, it is an overly simplistic solution, but it works.

VB.NET

Public

Class VBCalculator
   
Public Shared Function Add(ByVal a As Integer, ByVal b As Integer) As Integer
       
Return a + b
   
End Function
End
Class

C#

public

class CSharpCalculator
{
   
public CSharpCalculator()
   
{
    }
   
public static int Add(int a, int b)
    {
       
return a + b;
   
}
}

Test the solution. Woo hoo, isn’t that fun.

Making the calc a service

Now, your XBox Live buddy pings you and says he needs an addition application. You say "d00d, don’t code it, I have 1", only in hackereze. To do this, add a web service page to your application and add the following method:

VB.NET

<WebMethod()> _

Public Function Add(ByVal a As Integer, ByVal b As Integer) As Integer
   
Return VBCalculator.Add(a, b)
End Function

C#

[WebMethod]
public int Add(int a, int b)
{
   
return CSharpCalculator.Add(a, b);
}

You are now so SOA.

Recap

In this overly simplistic exercise, you moved from a simple web application to a SOA implementation. You can now have anyone in the world add using your service. NO, it is not real world, but imagine some real world possibilities.

What you need for SOA:

  1. Code that can work with a set message format for input and return a set message for output. In this example, the input was two integers and the output was a single integer. This is unusual for services, however, as you are generally dealing with a much larger set of data, at least in one direction. For example, you might want a zip code service that returns city, county, and state for a particular zip code.
  2. An interface to reach the code externally. In this case a web service. This could be remoting, however, or any other port listening code that can return a message. In the later two cases, you are getting more and more stuck. Remoting, currently at least, requires Microsoft clients and the port listening solution requires an agreed format between you and your partners.

The benefit of Remoting or proprietary code is speed, but the benefit is often very small. In general, I would aim for the web service implementation first and alter if you need the extra performance. In ASP.NET 2.0, web services run very fast and there is not much gain with Remoting in most instances. In addition, you can use UDDI as a name service and quickly add other machines that can service clients. Finally, switching to WCF is a simple matter of changing the UDDI pointers.

Until next time.