Monday, June 12, 2006

First impressions of C#/.NET

Now that I've been messing around with C# for a couple of weeks I figured it is time to report on some initial impressions. Today's topic: web services. The quicky summary is that I'm very impressed with the ease of putting together both a simple web service and client.

Writing a class which exposes methods via web service is just like writing any other class. The only difference is that you mark the methods you want exposed using the [WebMethod] attribute. For example, let's start with a very simple, classic example:


public class HelloWorld
{

public Service () {
}

public string HelloWorld()
{
return "Hello World!!";
}
}


To turn this into a service, you only need to make a few changes:


public class Service : System.Web.Services.WebService
{

public Service () {
}

[WebMethod]
public string HelloWorld()
{
return "Hello World!!";
}
}


The rest is taken care of for you, including generation of the WSDL. I come from a world where you start writing the WSDL by hand and then use it to generate stubs for your service code. Believe me, building services this way is a huge relief.

Now, coming from an environment like Amazon makes you immediately skeptical of anything this automated. You start to wonder if it can really perform and how hard it will be to do anything "outside the box". I'll be honest, at this point I don't know the answers. I do know that I was able to get a service running in about 30 minutes, which is a huge productivity win even if I have to get more hands on later in the development process.

What about the client? Writing the code to call the service is just as simple. Once you have your WSDL generated, you can just point one of the provided tools at it to generate your client code. Out of the box you get a client library that can call the service both synchronously and asyncrhonously. Nice.

0 Comments:

Post a Comment

<< Home