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

Rob*_*Rob 18 c# 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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

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>
Run Code Online (Sandbox Code Playgroud)

mar*_*c_s 26

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

1)元数据的服务行为:

<behaviors>
  <serviceBehaviors>
     <behavior name="Metadata"> 
        <serviceMetadata httpGetEnabled="true" />
     </behavior>
  </serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)

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

<service name="wcfLib.StockService" 
         behaviorConfiguration="Metadata">
     ....
</service>
Run Code Online (Sandbox Code Playgroud)

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

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

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

    <endpoint name="mex"
              address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
</service>
Run Code Online (Sandbox Code Playgroud)

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

  • 我已经在上面的帖子中提到的所有内容仍然得到相同的错误(对话框). (4认同)

atc*_*way 15

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

<service behaviorConfiguration="wcfLib.Service1Behavior" name="wcfLib.Service1">
Run Code Online (Sandbox Code Playgroud)

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

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