The design time features of Web Service Enhancements 3 (WSE 3) are not officially supported for Visual Studio 2008. The only reason I can find for this is that Microsoft would prefer you migrate your code to WCF. Fair enough, some might say, WCF is a better technology, isn't it? Well, it depends on what you call better, if you've developed a working product for a client using WSE 3, how do you justify the expense of upgrading the solution to WCF? How also, do you justify the work required to your Smart Client Update implementation that will be required to roll out .NET 3.0 to their 20,000 clients? Will those clients accept .NET 3.0 on their machines, i.e. are they still running Windows 2000, or have a corporate policy that may prevent this? The point is, although updating the software may be easy, this is only one small part of the problem.
For those in the same predicament here is the solution (or at least some pointers on how to write one)...
WSE 3.0 adds its proxy classes to the code generated for a web reference through a standard extension mechanism employed by the ServiceDescriptionImporter class which is invoked by the MSDiscoCodeGenerator custom tool.
Extensions for the ServiceDescriptionImporter class are configured within the application configuration file. For Visual Studio this configuration file is named "devenv.exe.config" and can be found in the same location as the main Visual Studio executable.
Here is the configuration required to add the WSE3 extensions.
<system.web>
<webServices>
<soapExtensionImporterTypes>
<add type="Microsoft.Web.Services3.Description.WseExtensionImporter,
Microsoft.Web.Services3, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</soapExtensionImporterTypes>
</webServices>
</system.web>
NOTE: When editing the "devenv.exe.config" file under Windows Vista you should make sure you have elevated permissions. If you do not elevate you permissions the file will be saved transparently and without warning to a mapped virtual directory, i.e. not to the same location you opened it from.
The next step is slightly trickier...; although we have configured the extension, by default it will not generate any code. The reason for this is that the extension queries a delegate (assigned by the WSE Visual Studio Addin on Visual Studio 2005) to determine if WSE has been configured for the project.
public class WseExtensionImporter : SoapExtensionImporter
{
public static WseExtensionImporter.IsWseReferencedInActiveProject
IsWseReferencedActiveProjectImplementation;
public static WseExtensionImporter.IsWseReferenced
IsWseReferencedImplementation;
public WseExtensionImporter();
public override void ImportMethod(CodeAttributeDeclarationCollection metadata);
public delegate bool IsWseReferenced(string rootNamespace);
public delegate bool IsWseReferencedInActiveProject();
}
To make the extension generate code we must attach an implementation to the IsWseReferencedInActiveProject property within the Visual Studio 2008 design environment. The easiest way to do this is to write a quick Addin using the Visual Studio 2008 Addin wizard. There are plenty of articles on how to do this elsewhere so I won't go into details.
Once the Addin wizard has completed, perform the following steps:
- Add Microsoft.Web.Services3 and VSLangProj to your project references.
-
Update the OnConnection method as follows:
public void OnConnection(object application, ext_ConnectMode connectMode,
object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
WseExtensionImporter.IsWseReferencedActiveProjectImplementation = delegate()
{
foreach (object activeProjectObj in (Array)_applicationObject.ActiveSolutionProjects)
{
Project project = activeProjectObj as Project;
if (project == null)
continue;
VSProject vsProject = project.Object as VSProject;
if (vsProject == null)
continue;
if (vsProject.References.Find("Microsoft.Web.Services3") != null)
return true;
}
return false;
};
}
3. Install and activate the Addin.
WSE Proxies should now be generated for all projects that include Microsoft.Web.Services3 in their references!!!