未检测到Web服务?

我试图托管这个服务,下面运行正常但是当我在一个不同的Visual Studio运行时打开一个新项目并试图添加一个它找不到任何东西的Web服务? 不是在指定的地址或本地机器上的任何东西? 以下代码似乎只在我在同一个解决方案中运行时才有效?

namespace Students { class Program { static void Main(string[] args) { // Create the address for the service Uri address = new Uri("http://localhost:8001"); // Create the binding for the service WSHttpBinding binding = new WSHttpBinding(); // Create the service object StudentService service = new StudentService(); // Create the host for the service ServiceHost host = new ServiceHost(service, address); // Add the endpoint for the service using the contract, binding and name host.AddServiceEndpoint(typeof(IStudentService), binding, "students"); // Open the host host.Open(); Console.WriteLine("Student service started"); Console.WriteLine("Press return to exit"); Console.ReadLine(); // Close the host host.Close(); } } } 

我尝试从新项目添加它(分离到当前解决方案)时得到的错误是这样的:

 The HTML document does not contain Web service discovery information. Metadata contains a reference that cannot be resolved: 'http://localhost:8001/'. There was no endpoint listening at http://localhost:8001/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. The remote server returned an error: (404) Not Found. If the service is defined in the current solution, try building the solution and adding the service reference again. 

当我下载这个案例研究(初学者项目)时,它没有任何网页或应用程序配置文件,它只是从控制台应用程序托管。

另请注意,当我尝试添加Web服务时,我正在运行该服务。

在ServiceHost中添加元数据交换行为。

 namespace Students { class Program { static void Main(string[] args) { // Create the address for the service Uri address = new Uri("http://localhost:8001"); // Create the binding for the service WSHttpBinding binding = new WSHttpBinding(); // Create the service object StudentService service = new StudentService(); // Create the host for the service ServiceHost host = new ServiceHost(service, address); // Add the endpoint for the service using the contract, binding and name host.AddServiceEndpoint(typeof(IStudentService), binding, "students"); // Add metadata exchange ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; host.Description.Behaviors.Add(smb); // Open the host host.Open(); Console.WriteLine("Student service started"); Console.WriteLine("Press return to exit"); Console.ReadLine(); // Close the host host.Close(); } } } 

http://wcftutorial.net/WCF-Self-Hosting.aspx

您需要使用有关服务的信息创建/更新app.config文件。 退房: http : //msdn.microsoft.com/en-us/library/ms734765.aspx

在这里阅读更多内容: https : //stackoverflow.com/a/4660531/1220302