mexHttpBinding - 直接将ServiceMetadataBehavior添加到配置文件或ServiceHost以启用对此合同的支持

问题描述 投票:12回答:3

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

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

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

根据微软的例子,我的服务托管在托管的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"/>

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

wcf wcf-binding config meta endpoint
3个回答
25
投票

请务必在配置的behaviorConfiguration元素中指定service,以便允许使用httpGethttpsGet

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

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

如果未明确指定服务的行为,则默认情况下不允许HTTP GET和HTTPS GET,并且不会公开您的元数据。


2
投票

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

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

并将baseaddress更改为https。

或者(反过来)将你的wsHttpbinding转换为basicHttpbinding,事情将开始为你工作。


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
© www.soinside.com 2019 - 2024. All rights reserved.