How to use WSE 3 in Visual Studio 2008

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: 

  1. Add Microsoft.Web.Services3 and VSLangProj to your project references.
  2. 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!!!

Comments

# re: How to use WSE 3 in Visual Studio 2008
Gravatar Hey, this is great!

Thank a lot, it works like a charm. I should only add an installer which makes sure devenv.exe.config is updated. Many thanks!
Left by Radu Crisan on 9/24/2008 1:28 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Thank you very much!!!
Left by Nogard on 10/30/2008 12:41 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar does not work !!! I can't see the toolswhen I create a newWeb Service or a Client !!!I don't Khnow Why
Left by Ayman on 11/2/2008 7:44 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar The solution does not add any menu items within visual studio (although you could add code yourself to do this). As long as you include the Wse3 assembly in your references it will generate a Wse3 proxy automatically. Look inside your proxy code file and you should see it...
Left by Jason Young on 11/3/2008 5:26 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar If after completing the steps above it still doesn't generate the proxy classes, try right clicking the web reference and choose "Update Web Reference". This generated the proxy classes for me. Thanks for the info, Jason!
Left by Daniel on 11/6/2008 3:15 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Great work! You saved my day.
BTW, shame on you Microsoft!
Left by Bo on 11/12/2008 5:07 PM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Hi,
I tried to install this code but it did not worked. WseExtensionImporter and ImportMethod give errors. Do you have full source code to install?
Left by omer yavuz on 12/5/2008 6:56 AM
# obuazycg
Gravatar obuazycg
Left by obuazycg on 12/12/2008 12:49 PM
# glpjgwxv - Google Search
Gravatar glpjgwxv - Google Search
Left by Pingback/TrackBack on 12/12/2008 12:49 PM

Leave Your Comment

Title*
Name*
Email (never displayed)
 (will show your gravatar)
Url
Comment*

Please add 3 and 2 and type the answer here:

Preview Your Comment.