以编程方式添加 WCF 服务项目项

发布于 2024-08-23 11:44:14 字数 805 浏览 2 评论 0原文

信息:C#、Visual Studio 2010 RC

如何通过代码将 WCF Web 服务项目项添加到我的项目中?

我可以添加一个代码类文件,没有问题:

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);
} 

但如果我尝试使用:

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

我会得到一个异常,无法找到它

系统找不到该文件 指定的。 (HRESULT 的异常: 0x80070002)

我从以下位置获得了 WebWcfService 名称:

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

我认为这与解决方案如何查找其项目项有关但我不知道该怎么做。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青春有你 2024-08-30 11:44:14

这是我在 上回答的http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/7f031537-f8c0-4281-bda1-c56cf86b2109

嗨,菲尔

因为WebWcfService是一个web
项目,它是 CSharp 的子类型
项目。所以我们需要找到
WebWcfService 这样。

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

如果还有什么不清楚的地方,请留言
请随时告诉我。

谢谢

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文