繁体   English   中英

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

[英]WCF service host cannot find any service metadata

我刚学习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服务主机找不到任何服务元数据...

知道它可能是什么?

配置文件:

<system.serviceModel>
   <services>
      <service behaviorConfiguration="wcfLib.Service1Behavior" name="wcfLib.Service1">
        <endpoint address="" binding="wsHttpBinding" contract="wcfLib.ser">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/wcfLib/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="wcfLib.Service1Behavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

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

1)元数据的服务行为

<behaviors>
  <serviceBehaviors>
     <behavior name="Metadata"> 
        <serviceMetadata httpGetEnabled="true" />
     </behavior>
  </serviceBehaviors>
</behaviors>

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

<service name="wcfLib.StockService" 
         behaviorConfiguration="Metadata">
     ....
</service>

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

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

<service name="wcfLib.StockService" 
         behaviorConfiguration="Metadata">
     ....

    <endpoint name="mex"
              address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
</service>

有了这一切,事情就应该没问题! :-)

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

<service behaviorConfiguration="wcfLib.Service1Behavior" name="wcfLib.Service1">

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

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

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

确保已启用HTTP激活

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

问候

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

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

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

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

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 <system.serviceModel> / <services> config section
ServicesSection services = ConfigurationManager.GetSection("system.serviceModel/services") as ServicesSection;

ServiceHost host = new ServiceHost(typeof(SelfHostedService.Service));

// enumerate over each <service> 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 <Enter> key to stop");
}
catch(Exception ex)
{
    Console.WriteLine(ex.Message.ToString());
}

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

暂无
暂无

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

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