13

我知道这已经被问过很多次,并且回答过很多次,但是,所有提供的应该工作的样本今天似乎都不想为我工作。

当我尝试启动主机时,我不断收到以下错误:

“在服务 TraceService 实施的合同列表中找不到合同名称‘IMetadataExchange’。将 ServiceMetadataBehavior 添加到配置文件或直接添加到 ServiceHost 以启用对此合同的支持。”

根据 Microsoft 的示例,我的服务托管在托管 Windows 服务主机中:http: //msdn.microsoft.com/en-us/library/ms733069%28v=vs.90%29.aspx

这是我漂亮而简单的配置:

  <system.serviceModel>
    <services>
      <service name="Daff.Lae.Service.TraceService">
        <endpoint address="" binding="wsHttpBinding" name="TraceService" contract="Contracts.Service.ITraceService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/TraceService" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="DefaultBehavior">
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

当然,如果我删除这一行,当没有错误时问题会变得更有趣:

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

任何帮助将非常非常非常感激:)

4

3 回答 3

25

请务必在配置元素中指定 abehaviorConfigurationservice允许使用httpGethttpsGet

我看到您已经定义了一个名为的 serviceBehavior DefaultBehavior- 现在您需要做的就是添加behaviorConfiguration="DefaultBehavior"service元素中,因此该行变为:

<service name="Daff.Lae.Service.TraceService" behaviorConfiguration="DefaultBehavior">

如果你没有为你的服务明确指定一个行为,HTTP GETs 和 HTTPS GETs 默认是不允许的,你的元数据也不会被暴露。

于 2011-09-20T21:51:39.273 回答
2

当您使用 WS-Http 时,您将绑定到 HTTPS 协议,因此您需要使用正确的 MEX 绑定;

<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 

并将基地址更改为 https 的。

或者(反过来)将您的 wsHttp 绑定转换为 basicHttp 绑定,然后一切都会开始为您工作。

于 2011-09-20T21:45:41.680 回答
0
`<services>
  <service  name="MyService.Service1" behaviorConfiguration="Service1" >

</services>
 `

 where MyService is the application name , Service1 is the default implementation class for IService1
 `
 <protocolMapping>
  //Remove any http or https bindings provided  
</protocolMapping>   
 `
It should help when you use WCF Application Project
于 2018-01-04T15:02:25.563 回答