WCF服务主机找不到任何服务元数据

我刚学习wcf,目前已经走到了这一步。

CS档案:

using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace wcfLib { [ServiceContract] public interface IfaceService { [OperationContract] int wordLen(string word); } public class StockService : IfaceService { public int wordLen(string word) { return word.Length; } } } 

然而,当我试图运行它时,它会弹出一个错误:

WCF服务主机找不到任何服务元数据……

知道它可能是什么?

配置文件:

                          

您需要在配置文件中包含以下内容:

1)元数据的服务行为

        

2)在服务的配置中引用服务行为

  ....  

*配置文件中服务标签中的名称值必须与实现合同的物理类名称相同。 请记住,如果类名更改,请确保更改此值以匹配。

3)MEX的端点(元数据交换)

  ....   

有了这一切,事情就应该没问题! 🙂

我得到了完全相同的问题,并且正在大力浏览我的配置, 所有内容都与元数据端点等内联。问题是什么? 这一行:

  

name必须,必须具有实现合同的物理类的名称。 我忘记了…再一次,任意地命名它认为它可能是任何字符串。 因此,在上面的情况下,实现类必须命名为Service1 。 如果类名更改,请确保更改此值。

这就像WCF 101的东西,即使我自从在Framework 3.0中使用CTP以来一直在做WCF,我仍然被它烧焦了。 等等…

创建此问题的最简单方法是简单地重新计算您的接口名称。 它肯定会更改项目中的实例名称,但无法更新web.config文件。 要重新创建一个新服务,重命名你的界面并重击F5,繁荣,元数据对话框出现:-)答案如上所述,只需记住手动更改你的web.config文件。

问候

我启用了HTTP激活。 确保你有它。

确保已启用HTTP激活

听起来您需要添加元数据交换端点:

http://en.csharp-online.net/WCF_Essentials%E2%80%94Metadata_Exchange

默认情况下,Visual Studio将尝试使用您的新服务设置客户端/测试ui。 要做到这一点,需要了解您的服务提供的结构和方法。 这是通过使用标准WSDL格式的定义来实现的。 但是,默认情况下,WCF不会发布此数据。

您必须为acehive设置metadataexchange端点行为。

在这里发布您的配置文件,我们可以协助,或谷歌/堆栈搜索WCF中的metadataexchange和wsdl

我收到此错误是因为我的服务名称错误。 使用netTcpBinding和mexTcpBinding与httpGetEnabled = False然后工作。

 // get the  /  config section ServicesSection services = ConfigurationManager.GetSection("system.serviceModel/services") as ServicesSection; ServiceHost host = new ServiceHost(typeof(SelfHostedService.Service)); // enumerate over each  node foreach (ServiceElement aService in services.Services) { Console.WriteLine(); Console.WriteLine("Name: {0} / Behavior: {1}", aService.Name, aService.BehaviorConfiguration); // enumerate over all endpoints for that service foreach (ServiceEndpointElement see in aService.Endpoints) { Console.WriteLine("\tEndpoint: Address = {0} / Binding = {1} / Contract = {2}", see.Address, see.Binding, see.Contract); //host.AddServiceEndpoint( } } try { Console.WriteLine("Service EndPoints are: "); foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { Console.WriteLine("{0} ({1})", endpoint.Address.ToString(), endpoint.Binding.Name); } host.Open(); Console.WriteLine(string.Concat("Service is host at ", DateTime.Now.ToString())); Console.WriteLine("\n Self Host is running... Press  key to stop"); } catch(Exception ex) { Console.WriteLine(ex.Message.ToString()); } 

如果仍然无法工作,那么删除当前配置文件并使用其默认名称App.config重新创建它,这是有效的。

如果以编程方式创建服务主机并忘记将[ServiceContract]和[OperationContract]属性添加到接口协定,也可能会出现同样的错误。

我知道这是一个古老的问题,但我想我会在这个问题上给出2美分,因为它刚好发生在我身上。

我以某种方式将构建平台从“任何CPU”更改为“x86”以用于Web服务本身。 第二个我把它改回“任何CPU”,它解决了问题。