views:

242

answers:

1

Info: C#, Visual Studio 2010 RC

How can I add a WCF Web Service Project Item to my Project via code?

I can add a Code Class file no problem with:

string csItemTemplatePath = soln.GetProjectItemTemplate("CodeFile", "CSharp");

try
{
    projectItems.AddFromTemplate(csItemTemplatePath, fileName);
}
catch (Exception ex)
{
    // This is just testing, don't shoot me
    MessageBox.Show(ex.Message);
} 

but if I try it with:

string itemTemplatePath = soln.GetProjectItemTemplate("WebWcfService", "CSharp");

I get an exception that it can't be found

The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

I got the WebWcfService name from:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\1033

I pressume it is something to do with how the Solution looks for it's project items but I can't figure out how to do it.

+1  A: 

This was answered for me on http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/7f031537-f8c0-4281-bda1-c56cf86b2109

Hi, Phill

Because WebWcfService is a web project, which is a subtype of CSharp project. So we need to find the WebWcfService this way.

string path = soln.GetProjectItemTemplate("WebWcfService.zip", CSharp/Web");

If you have anything unclear, feel free to let me know.

Thanks

Chao

Phill Duffy