简体   繁体   English

在解决方案中发现WCF服务

[英]Discover WCF services in Solution

I have a solution with a WCF service which works fine. 我有一个WCF服务的解决方案,工作正常。 I have added a small console app in the solution which needs to have a Service reference to the service in the same solution. 我在解决方案中添加了一个小型控制台应用程序,需要在同一解决方案中为服务提供服务引用。 It discovers the service but obviously can't connect to it as the service is not running. 它发现服务但显然无法连接到它,因为服务没有运行。 How in Visual Studio 2010 I can have the service running in the solution and at the same time add a service reference in the same solution? 在Visual Studio 2010中我如何在解决方案中运行服务,同时在同一解决方案中添加服务引用?

Assuming the Client Application is in the same solution as the WCF Service project, r-click the client application and choose "Add Service Reference". 假设客户端应用程序与WCF服务项目位于同一解决方案中,请单击客户端应用程序并选择“添加服务引用”。

A dialogue is displayed allowing you to select your Service by clicking the button in the top right labelled "Discover". 将显示一个对话框,您可以通过单击右上角标有“发现”的按钮来选择服务。

Assuming the binding is correctly set and available for the WCF Service (via an app.config file or similar) the IDE will automatically host the service for you. 假设绑定已正确设置并可用于WCF服务(通过app.config文件或类似文件),IDE将自动为您托管服务。 - note, the app.config should be located within the WCF Service project unless there is a designated host already available in another project within the solution. - 请注意,app.config应位于WCF服务项目中,除非解决方案中的另一个项目中已有指定的主机。

If there are any issues hosting the service, a new dialogue will appear, with the right hand column for your service endpoints saying "Error". 如果托管服务有任何问题,将出现一个新的对话框,您的服务端点的右侧列显示“错误”。 Clicking the errored line will explain why there is an issue and hopefully help you to resolve it. 单击错误行将解释为什么存在问题并希望帮助您解决问题。

Not true. 不对。 WCF Service projects can self host themselves within the IDE for the purpose of adding service references WCF服务项目可以在IDE中自行托管,以便添加服务引用

Yes, if the project with service is the main project of the solution, but if we want to start a client app from the same solution we need to set main project to client app and as result wcf app won't start by itself, so we need helper class that hosts wcf. 是的,如果带有服务的项目是解决方案的主要项目,但是如果我们想要从同一个解决方案启动客户端应用程序,我们需要将主项目设置为客户端应用程序,因此wcf应用程序不会自动启动,所以我们需要托管wcf的辅助类。

如果您正在尝试构建一个在同一解决方案中自行承载WCF项目的控制台应用程序,请使用“添加引用”(而不是“添加服务引用”),在解决方案下,您将在解决方案中找到该服务。

Right-click on the project in the Solution Explorer, and select Unload project 在Solution Explorer中右键单击该项目,然后选择Unload project

Right-click the project again (this time the node will end in (unavailable) ) and choose Edit xxxxx.csproj 再次右键单击该项目(此时节点将以(不可用)结束)并选择Edit xxxxx.csproj

In the first section, add the following line: {3D9AD99F-2412-4246-B90B-4EAA41C64699};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 在第一部分中,添加以下行:{3D9AD99F-2412-4246-B90B-4EAA41C64699}; {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}

Save and close the file Reload the project by right-clicking it again and choose Reload. 保存并关闭文件通过再次右键单击重新加载项目,然后选择“重新加载”。 You should then be able to use the "Discover services in solution" functionality 然后,您应该能够使用“在解决方案中发现服务”功能

Run the application and attach the debugger to wcfsvchost.exe 运行该应用程序并将调试程序附加到wcfsvchost.exe

http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.aspx http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.aspx

You need to host your service. 您需要托管您的服务。 Create a class that will do it in the same solution 创建一个将在同一解决方案中执行此操作的类

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

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