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
# re: How to use WSE 3 in Visual Studio 2008
Gravatar I have implemented the code and config changes outlined but I can't seem to understand what you need to do to tell the web service that was created in VS2008 that it is WSE enabled now. Normally this is done with the COntext menu but since there isn't one I need to know what needs to be added to web.config.

Thanks
Left by Santiago Perez on 1/7/2009 6:22 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Please note that you MUST add a Web Reference, not a Service Reference!! This is an important step. To do so in VS 2008 Right click in Solution Explorer click 'Add Service Reference...' and then click Advanced on the bottom left, then click 'Add Web Reference...' Hope this helps someone, this caveat ate up 10 minutes of my time.
Left by Jose Paulino on 1/8/2009 2:44 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar I love this, it sucks its not even made google first page as it the perfect solution and works!

I found from the MSDN forums.
Left by Chris on 1/17/2009 9:10 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar When I compile my Add-in I'm getting the following error. Any help? Thanks.

The type 'System.Web.Services.Description.SoapExtensionImporter' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Left by Kiks on 1/20/2009 9:19 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar aaah! bummer...

I was looking to add a reference for Microsoft.Web.Services but the compiler is looking for System.Web.Services. Just adding this reference compiled clean.

Thanks for the article!
Left by Kiks on 1/21/2009 4:29 AM
# Good Article, But...
Gravatar This is a good article. It will help anyone who actually needs to use WSE.

However, for the benefit of those who don't really need WSE (perhaps they learned about WSE through a Google search), it should be mentioned that WSE is obsolete. "Obsolete" meaning there will be no support of it in future releases of Visual Studio, and that there will probably be only critical security fixes made to the code.

WCF is an improvement over WSE in almost every way (DIME support being one case where WSE is better).
Left by John Saunders on 1/21/2009 3:21 PM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Baie Dankie. (something for you to google).

Would have not been able to solve this issue without this post.

Thanks again.
Jeremy
Left by Jeremy Lunn on 1/29/2009 7:46 PM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar John Saunders, nobody is saying that WCF isn't an improvement over WSE. Everybody already knows WSE is obsolete. That's not the issue though, you see? Read the first paragraph of this article again, please.

Eric.
Left by Eric Sanchez on 2/12/2009 12:54 PM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar So, when you create the WseExtensionImporter class, do you just leave the constructor and ImportMethod methods empty?
Left by Chachi on 2/24/2009 5:33 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar yeah, that was a dumb question... nevermind :)
Left by Chachi on 2/25/2009 9:44 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Could you please provide a link to download the Addin?

I tried this solution but did not work for me.

Somehow the plugin is not working and it is still not creating the Wse proxies.
Left by Tiago Margalho on 3/1/2009 5:34 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar I'm having some problems with creating this addin manually. So could you please provide a link to the addin itself or its source code?
Left by Aleksey Larchenko on 3/5/2009 11:57 PM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar am i wrong, or does just simply updating the web references generate the Wse classes for you?
Left by Eric Sanchez on 3/11/2009 9:52 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Updating the web references should generate the Wse classes for you, as long as you have added a reference to Microsoft.Web.Services3 in your project.
Left by jyoung on 3/11/2009 7:38 PM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Thank You Very Much.. It works like Charm........
Left by Neo on 3/24/2009 4:37 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar I am getting (2) errors when making the add-in:

1. MyAddin1.WseExtensionImporter.WseExtensionImporter()' must declare a body because it is not marked abstract, extern, or partial

2.MyAddin1.WseExtensionImporter.ImportMethod(System.CodeDom.CodeAttributeDeclarationCollection)' must declare a body because it is not marked abstract, extern, or partial


I have tried adding this class right in the Connect.cs class and I also tried making it its own class file, but each gives the same error output.

Does anyone know what I am doing incorrectly?
Left by atconway on 3/27/2009 8:59 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Actually I just figured out the last (2) issues. The both just need an open and close body bracket after the names. I didn't realize one was the constructor of the class, and the other (ImportMethod) was just a Sub that had no return. I typically program in VB.NET, so a few easy things threw me off a bit.

Now it builds fine, and even shows up in the 'Add-In' menu in VS.NET 2008 (I chose those options in the Add-In wizzard).

However, upon refeshing the web reference (or deleting and re-adding), the WSE instance is still NOT created. No errors, just nothing happens. I also added those .config entries as well. Any ideas on what I may be missing?
Left by atconway on 3/27/2009 9:21 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Is there some way to trace what is happening, because my add-in builds and installs well, but the new proxy code (after updating reference) is never generated. No errors or problems, but I never get the set of classes that inherit from 'Microsoft.Web.Services3.WebServicesClientProtocol' just the ones from 'System.Web.Services.Protocols.SoapHttpClientProtocol'. Any ideas?
Left by atconway on 3/30/2009 3:27 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar I created an addin, but "Microsoft.Web.Services3" is not found in .net assemblies. Should I search for the dll somewhere else?
Left by Sergej Andrejev on 4/9/2009 3:05 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar After running into similar issues as atconway, I got the Addin to build, installed it in VS2008, added the configuration to devenv.exe.config and still my web references are still inheriting from SoapHttpClientProtocol when I add a web reference. My case is a little different as I am trying to consume the WSE enable webservice from an Adobe Flex application. As soon as I add the WSE configuration elements in my web.config, I am getting an error when I try to call even a non-WSE enabled webservice.
Left by VariableOp on 4/17/2009 1:51 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Take a look at the post from DotNetSetp blog at (dotnetstep.blogspot.com/.../...-visual-studio.html) as it doens't require the need to create an AddIn, rather just changin the existing AddIn definition.
Left by Paulo Santos on 5/13/2009 3:00 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Hello,

I'm having this problem with a VS2008 program using VB.

I'm not sure of what to do with the devenv.exe.config file and the other steps.

Does anybody have a more detailed, step by step, explanation of how to accomplish this with a VB program that consumes a web service.

Any help would be gratefully appreciated.

Thanks,
Tony
Left by Tony Girgenti on 5/16/2009 11:53 PM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Excellent post. Thank you.

Couple things to note for those of you struggling with this scenario:
1. When your add-in is created and you test it - error when loading the add-in may be related to the path of the dll in your addin test file. Run the add-in and the DLL off your local drive (C:\) instead of a network drive. Seems there is a bug in VS causing trust issues on network installed add-ins.
2. Keep all 3 check-boxes of the add-in wizard unchecked to create the simplest possible add-in. (command line, menu item and another one).
3. Follow instructions from Jose Paulino's post above. The steps work.

Follow the instructions above and things will work just fine!
Left by VC on 6/1/2009 6:16 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Thank you so much for the post.
It works fine and generates the proxy but I need to use UsernameToken authentication for the webservice. For this I have to add the following section to my web.config:

<microsoft.web.services3>
<diagnostics>
<trace output="OutputTrace.webinfo" input="InputTrace.webinfo"
enabled="true" />
</diagnostics>
<policy filename="wse3policyCache.config" />
</microsoft.web.services3>

This section generates me configuration error:
Parser Error Message: Unrecognized configuration section microsoft.web.services3

I added wse3 reference to my project and my web.config file also has
<section name="microsoft.web.services3" type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />


Am I missing something? Could you help? I am going nuts with this problem.
Thanks
Left by Navi on 6/8/2009 3:56 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Fantastic - thanks.

One caveat I encountered - I had to add the Microsoft.Web.Services3 dll to the GAC for VS.NET 2008 to start happily.

Left by Neil on 6/18/2009 2:55 AM
# Enabling Web Services Enhancements in Visual Studio 2008 &amp;laquo; MikeFoden.com
Gravatar Enabling Web Services Enhancements in Visual Studio 2008 &amp;laquo; MikeFoden.com
Left by Pingback/TrackBack on 6/27/2009 2:39 PM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar Great post. Thanks so much!
(Don't forget to add a reference to the System.Web.Services assembly.
and include
using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Description;
using VSLangProj;
using System.Web.Services; to the add-in)
Left by Doug on 7/2/2009 2:49 PM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar You do not have to create a new add in for the code generation to work. You can edit the Addin file to make it Visual Studio 2008 compatible. The steps are available here - bijesh.net/post//using-wse-3-in-visual-studio-2008
Left by Bijesh on 7/7/2009 9:37 AM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar To Eric Sanchez: Sorry for replying late - I just saw your reply.

The unfortunate fact is that not "everybody" knows that WSE is obsolete. Just a couple of weeks ago, I replied on the http://forums.asp.net/28.aspx to someone who was just starting development with WSE. I asked him if he knew it was obsolete, and he said he had not known that.

The fact is that many people depend on Google. Unfortunately, Google indexes current information, as well as outdated information. Someone searching for "Web service security" is quite like to find links about WSE right on the first page of search hits.
Left by John Saunders on 8/13/2009 4:52 PM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar This is a really annoying problem. I'm in the process of converting a huge project to .Net 3.5 and VS2008. Although, part of this upgrade will include moving from WSE 3 to WCF, I really wanted to upgrade everything to .Net 3.5 and then test before moving to WCF - in fact I've got a number of web services so I'll probably convert them to WCF one at a time. As part of the conversion process, VS2008 removed the WSE version of the web service proxies. Although, because everything is under source control, I could revert the changes to the reference.cs files, the next time I opened the solution in VS, the conversion process kicked in again.

Implementing what points you wrote in your post resolved the problem. Thankyou! The only things that I needed to do extra were to add a reference to System.Web.Services in the addin project and I had to update my web references to get VS2008 to recreate the WSE web service proxies.
Left by Simon on 10/13/2009 9:03 PM
# re: How to use WSE 3 in Visual Studio 2008
Gravatar It helped me with ocean of knowledge so I really believe you will do much better in the future I appreciate everything you have added to my knowledge base.Admiring the time and effort you put into your blog and detailed information you offer!
Left by best online slots sites on 11/13/2009 12:19 AM

Leave Your Comment

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

Please add 7 and 8 and type the answer here:

Preview Your Comment.