简体   繁体   English

如何在VS 2010中向控制台应用程序添加设计时服务引用?

[英]How to add a design time service reference to a console application in VS 2010?

I'm trying to create a simple WCF application. 我正在尝试创建一个简单的WCF应用程序。 My service interfaces and implementations are in class libraries. 我的服务接口和实现在类库中。 I have written a very simple console application that acts as a server host. 我编写了一个非常简单的控制台应用程序,它充当服务器主机。

Now I have created a silverlight client, and I'm trying to add a service reference, using the App.config in the console application, but the configured services are not showing up in the Discover->Services In Solution. 现在,我已经创建了一个Silverlight客户端,并且尝试使用控制台应用程序中的App.config添加服务引用,但是配置的服务未显示在“发现”->“解决方案中的服务”中。

They do show up if I create a WCF class library to contain my services, but not a normal class library with an app.config. 如果我创建一个WCF类库来包含我的服务,它们就会显示出来,但是没有一个带有app.config的普通类库,它们就会显示出来。

I can run the console application and add the service reference then, but that seems a bit clumsy. 我可以运行控制台应用程序,然后添加服务引用,但这似乎有点笨拙。

What are the rules for adding design-time service references? 添加设计时服务引用的规则是什么?

Edit 编辑

Visibility of a project to design-time discovery appears to be controlled by the following project types: 项目对设计时发现的可见性似乎受以下项目类型的控制:

{3D9AD99F-2412-4246-B90B-4EAA41C64699};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} {3D9AD99F-2412-4246-B90B-4EAA41C64699}; {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}

(adding these to a csproj requires that it contains at least one service). (将这些添加到csproj要求它至少包含一项服务)。

Another rule appears to be that the service types have to be in the same assembly as the app.config that references them. 另一个规则似乎是,服务类型必须与引用它们的app.config位于同一程序集中。

I believe Visual Studio uses different project types in your solution (metadata stored either in the solution-/project file or both) to identify potential candidates. 我相信Visual Studio在您的解决方案中使用不同的项目类型(元数据存储在解决方案/项目文件中或同时存储在这两者中)来识别潜在的候选对象。 If you create a console application Visual Studio won't treat it as if it could contain service reference, though as I think you've already figured out, changing the target type after the project has been created doesn't seem to have this effect because it doesn't invalidate that metadata. 如果您创建一个控制台应用程序,Visual Studio不会将其视为可能包含服务引用,尽管正如我认为您已经知道的那样,在创建项目后更改目标类型似乎没有这种效果。因为它不会使该元数据无效。

Create two new projects, one of each and compare the two files with a diff tool or just notepad. 创建两个新项目,每个新项目之一,然后使用差异工具或记事本比较两个文件。 See if copy the change between the projects and reloading (or even restarting VS) changes this behavior. 查看是否在项目之间复制更改并重新加载(甚至重新启动VS)是否会更改此行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM