WSE 2.0 Item Templates for Visual Studio .NET 2003

UPDATE: I have updated the msi in the workspace to provide both VB.NET and C# templates.

Ever wanted a simpler way to create SoapClient and SoapService classes without having to go look in the online WSE 2.0 documentation or WSE 2.0 Messaging Hands On Labs to find the exact syntax?  Want a quick way to create a SoapReceiver without coding the class, then opening the add-in dialog in Visual Studio .NET to enable the project for WSE 2.0?

I have received this request from several customers, so I thought I would go ahead and provide it to everyone.

When you add a new SoapReceiver to your project, this item template will set a reference to several dlls (like the WSE DLL) and will generate a class that looks like the following:

using System;
using System.Web.Services.Protocols;
using Microsoft.Web.Services2;
using Microsoft.Web.Services2.Messaging;
using Microsoft.Web.Services2.Addressing;

namespace WindowsApplication6
{
/// <summary>
/// Summary description for NewWSEReceiver2.
/// </summary>
public class NewWSEReceiver2 : SoapReceiver
{
public NewWSEReceiver2()
{
//
// TODO: Add constructor logic here
//
}

protected override void Receive( SoapEnvelope message )
{
// string actionValue = "urn:contoso:com/MyMethod";
// Action action = new Action(actionValue);
//
// if(message.Context.Addressing.Action.Equals(action))
// {
// // TODO: Add method logic here
// }
// else
// {
// throw new SoapException("Invalid wsa:Action specified",SoapException.ClientFaultCode,SoapContext.Current.Actor.ToString());
// }
}
}
}
WSE 2.0 Item Templates for Visual Studio .NET 2003

When you add one of these items to your project, the item automatically sets a reference to microsoft.web.services2.dll if it is not already set.  This saves you the time of right-clicking the project, choosing the "WSE Settings 2.0..." tab, clicking the "Enable the project for Web Services Enhancements" checkbox, then going back into your project and adding a class that derives from SoapReceiver, SoapClient, or SoapService. 

This really was a simple exercise of following along with Chris Sells' article on Adding Custom Project Item Templates to VS.NET.  Once I got the first template working, adding additional templates was more repetition than invention.  Once you see the artifacts that the MSI package creates, then read Chris' article, you should see that there really is very little magic.

The MSI installer installs the following artifacts.  I didn't provide a source redistributable because, well, there's really nothing binary, nothing is compiled... everything it installs is in the form of plain-text files that you can inspect yourself.  The tree of installed artifacts looks like the following:

Tree view of artifacts installed to support WSE 2.0 Templates

The only thing that I did in my implementation that Chris' article did not show was how to set the references to assemblies.  A little spelunking into common.js in the VC# directory yielded the following addition to default.js:

function AddReferencesForWSE(oProj)
{
var refmanager = GetCSharpReferenceManager(oProj);
var bExpanded = IsReferencesNodeExpanded(oProj)
refmanager.Add("System.Web");
refmanager.Add("System.XML");
refmanager.Add("System.Web.Services");
refmanager.Add("Microsoft.Web.Services2");
 if(!bExpanded)
CollapseReferencesNode(oProj);
}

Note that the current version only installs to the "C:\Program Files\Microsoft Visual Studio .NET 2003\VC#" directory.  It only supports Visual Studio .NET 2003, and only supports C# (currently... I am working on a VB version that I should have up in the next couple of days).

You can download the ZIP archive containing the MSI package for the artifacts on the WSETemplates GotDotNet.com workspace.

UPDATE: I have updated the msi in the workspace to provide both VB.NET and C# templates.