Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Web References in Project Templates

I'm building a custom .Net project template using VS.Net 2003. I've modified the default.js file in my project template to programmatically add DLL references when a new project is created using the template, using syntax like :

function AddDLLReferences(oProj)
{
var refmanager = GetCSharpReferenceManager(oProj);
refmanager.Add("System.Web");
refmanager.Add("System.Web.XML");
refmanager.Add("System.Web.Services");
}

1 (most importantly). How can I add references to a -webservice-? Is it some variant of the reference manager's Add method, or is it something else?

2 (less importantly). Where can I find good documentation on the functions / objects used by default.js and common.js? MSDN seems to be pretty quiet on the subject.

.Not
Monday, April 25, 2005

A web reference is not actually a reference - it's a proxy. When you add a web reference to your project, VS generates proxy classes based on the web service's WSDL.

It would take some effort, but I suppose you could write some javascript to parse the web service URL and build a proxy class, or maybe just run wsdl.exe and add the generated code to your project.

If all else fails, Dr. Ex can help you....

http://msdn.microsoft.com/vstudio/extend/drex/default.aspx

Jeff Mastry
Monday, April 25, 2005

Just as a clarification, I should have detailed the GetCSharpReferenceManager function I referenced above. I constructed it as :

function GetCSharpReferenceManager(proj)
{
  var StudioProject = proj.Object;
  var refmanager = StudioProject.References;
  return refmanager
}

Anyway, I don't have a problem forcing the project template wizard to move the .wdsl and other webservice files over when the project is created, but I still can't figure out how to "register" the webservice within the project.

VStudio's Solution Explorer doesn't display the webservice automatically, even though the files are in the correct place, and I can't reference its namespace (even adding an appsettings key to reference it in the web.config). What am I missing?

.Not
Monday, April 25, 2005

I looked at a project file for a project that has web references and noticed that the files are listed in the Files/Include section. Perhaps after generating the files with wsdl.exe, you just need to add each file to the project and set the appropriate attributes?

Not very helpful I know....

Jeff Mastry
Tuesday, April 26, 2005

Actually, I figured it out.

The project object returned by CreateVSProject (defined in common.js) is, in and of itself, incapable of adding web references. However, if you use the syntax project.Object.AddWebReference(<URL>), -that- works (and returns a webservice reference in the form of a projectItem object). The key is using the .Object property. If you don't use the explicit reference to .Object, the project can't actually invoke this particular method (though it -can- invoke many of the other project methods, or so it seems).

Incredibly irritating, and (as far as I could see) undocumented. However, it means that I don't even have to mess around with the wsdl files -- they get built automagically by the AddWebReference method.

Anyway, thanks for your efforts on my behalf.

.Not
Tuesday, April 26, 2005

Wow - good find. How in the world did you figure out that "Object" was required? :)

Here's the link to the docs on AddWebReference in case anyone ever needs it:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vxlrfvslangprojvsprojectaddwebreference.asp

Jeff Mastry
Tuesday, April 26, 2005

hi all,

  can anyone help me to develop custom web project template using EnvDTE.Project.
 
  thanks in advance.
Gaurang

Gaurang
Thursday, June 09, 2005

*  Recent Topics

*  Fog Creek Home