VS2008 extension for SharePoint 2007

Last week I started a development project based on SharePoint 2007 and for the first time for this kind of projects I am using Visual Studio 2008 and the corresponding extensions for SharePoint. Among other things, these extension add some projects templates. Yesterday I noticed that these project templates are class library projects, but with a particular behavior. When you right click on the project file there is a “Deploy” option, witch does not exist in the case of regular class library projects. At first I thought that it was because of some properties in the configuration of the project, but I checked it and there was…nothing. So I opened the project file with a text editor and I noticed that the SharePoint project file had the following additional line:

<ProjectTypeGuids>{593B0543-81F6-4436-BA1E-4747859CAAE2};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

It seems that this line is the magic item that adds the “Deploy” option in the VS project file menu. I will try to get some more information about this curiosity.

Error handling in Web Services (ws-part 4)

This post wasn’t part of the original series, but I have decided to add it because of a project I am working on these days.

Most of the times I have been involved in the server side of web services, developing web services, but in this opportunity I am consumer of web services.

When reviewing the technical specs of the web services I have to consume I found that each web service returned a complex type that contains the following fields:

  • Result: an integer that represents the result of the invocation, (1) successful invocation, (2) Invalid parameters, (3) Internal service error, and so on.
  • Errors: in case the result be (2) it details the name of the parameters that are not valid.
  • Data: the business information expected as the result of the invocation.

This approach is not bad, but I feel it like been reinventing the wheel. Maybe it is because of my object-oriented programming background. I am used to use exceptions to handle errors. Most of the technologies that give support to soap protocol provides a way to work  with exceptions to manage errors.

When you call a web service and an error raises during the process, a soap fault message should be used to communicate the error. This fault message contains:

  • Code: that allows the fault to be classified in one of the following categories: VersionMismatch, MustUnderstand, DataEncodingUnknown, Sender and Receiver.
  • Reason: provides a human-readable explanation of the fault
  • Node: provides information about which SOAP node on the SOAP message path caused the fault to happen
  • Role: identifies the role the node was operating in at the point the fault occurred.
  • Detail: is intended for carrying application specific error information

No matter what technology you used to work with SOAP, most of them provide a class to represent a Soap Fault, that is typically called Soap Exception. In the case of .NET there is a SoapException. This way if you are using .NET to consume a web service using Soap, .NET will generate a proxy object for you to call the web service, when you call this service you should do it inside a try-catch block adding 2 catch statements one catch for a SoapException and another catch statement for a System.Net.WebException, in case that no connectivity can’t be established.

Something is changing…

Over the last two years some interesting things have happened in the .net community, among these things I would like to highlight the followings:

  • Greater interest in Domain Driven Design in contrast to the traditional MSDN Data driven way. This has stimulated the adoption of certain design techniques like DI and AOP among other.
  • As a consequence of the previous point there has been a wider adoption and diffusion of open source tools (beyond the P&P application blocks). Tools like NHibernate, Castle and Spring.Net have proven to be high quality products providing efficient solutions for typical problems in enterprise development. Event Microsoft (in a certain way) has recognized these facts, I think ASP.NET MVC is an example of this.
  • Massive adoption of agile development practices like continous integration, unit testing, pair programming and iterative development among others.

I think that evidence of these facts are the creation of the ALT.NET community and the publication of the excellent book «Foundations of Programming» by Karl Seguin.
I see this as great progress for the maturity of the community and the quality of its developments.

Ping Pattern for Services

En los últimos meses he estado trabajando mucho con servicios WCF. Si bien en el ambiente de desarrollo no he encontrado mayores inconvenientes, si he encontrado algunos a la hora de desplegar los servicios en un ambiente de test/producción (win2003). Dichos inconvenientes se han debido principalmente a las diferencias existentes entre web server de Visual Studio y el IIS 6, existente en Windows 2003.

En más de una ocasión me encontré con servicios que en el ambiente de desarrollo se ejecutaban perfectamente y al desplegarlos en un ambiente de test no. En algunas ocasiones la diferencia estaba en cuestiones de configuración de WCF, mientras que en otras ocasiones en cuestiones relacionadas a la funcionalidad del servicio en sí.

Para poder distinguir rápidamente la causal del error, decidí agregar a cada servicio una operación "Ping" que simplemente, sin recibir parámetro alguno, devuelva la hora actual. De esta forma una vez desplegado el servicio, invocando a la operación Ping yo podía descartar cualquier problema relacionado a la configuración de WCF.

[OperationContract]
public string Ping()
{
    return DateTime.Now.ToString();
}

Después de haber aplicado esta receta en reiteradas ocasiones ya la he agregado a mi librito de prácticas útiles para el desarrollo de servicios.

 

Enjoy it!

Embedded Resources

Sometimes your assembly on runtime depends on a file, like a image or a simple text file. To manage this file, you could store its location in the application configuration file, and then load your file by reading its location from configuration. Another option is to embedded the file as a resource in your assembly and then use the following code snippet to load it.

System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream(«NameOfTheFile»);

Lets see an example. Suppose an assembly called Model.dll that requires a file called TextFile.txt that is part of the same visual studio project. First of all you should define that file as an embedded resource (properties->build action = embedded resource). Then in your code, when you need to access this file you can load it this way:

System.IO.Stream fileStream = this.GetType().Assembly.GetManifestResourceStream(«Model.TextFile.txt»);
System.IO.StreamReader sr = new System.IO.StreamReader(s);
string fileContent = sr.ReadToEnd();
fileStream.Close();

Note that the name of the assembly has been appended to the of the file. One you have read the contents of the file, remember to close the stream

Desarrollo con .NET 1.1: Herramientas de soporte

A pesar de que la versión actual de .NET es la 3.5, algunos clientes aún continúan trabajando con la versión 1.1. Precisamente en este momento me encuentro trabajando en uno proyecto así. Adicionalmente al uso de dicha tecnología, nos hemos visto impedidos de utilizar nuestro ambiente de desarrollo típico, montado sobre TFS, lo cual nos obligó a montar un ambiente alternativo. Después de un breve repaso de las necesidades del proyecto terminamos armando nuestro ambiente con los siguientes componentes.

El hecho de trabajar con .NET 1.1, ya de movida nos lleva a utilizar Visual Studio 2003.

Como framework de pruebas unitarias, elegimos NUnit y logramos integrarlo con VS2003 para poder depurar mientras ejecutamos las pruebas.

Como controlador de versiones decidimos utilizar Subversion, por considerarlo la mejor alternativa descontando TFS y suma a su amplia difusión.

Como cliente del subversión estamos utilizando TortoiseSVN, ya que las experiencias que hemos tenido con el plug-in the ANK no han satisfactorias.

Para la automatización de los builds, estamos utilizando NAnt.

Como es herramienta colaborativa estamos utilizando Trac. De esta herramienta utilizamos principalmente la funcionalidad de wiki y la planificación de milestones. Si bien esta herramienta cuenta con un sistema de tickets que puede utilizarse para tracker el progreso del proyecto, hemos preferido utilizar un SUPER excel ajustado para trabajar a lo SCRUM.

Toolkit de introducción a .net

Un buen punto para empezar a introducirse en el mundo .net es el programa del desarrollador 5 Estrellas:

http://www.mslatam.com/latam/msdn/comunidad/dce2005/

Este programa, va guiando al estudiante, de forma progresiva, comenzando casi de cero, y llegando incluso a exponer cuestiones de web services y conceptos de arquitectura.

Para poder ejercitar y seguir el curso a un buen ritmo, es necesario contar con el Visual Studio 2005. Si usted a un no cuenta con una versión del mismo, puede descargar el Visual Web Developer en forma gratuita de la siguiente ubicación.

http://msdn.microsoft.com/vstudio/express/downloads/

Finalmente es importante que gradualmente y al menos una vez por semana visite los siguientes sitios de referencia:

http://www.microsoft.com/practices
http://www.theserverside.net