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

发布于 2024-12-05 07:20:55 字数 1682 浏览 2 评论 0原文

我知道这个问题已经被问过很多次,也被回答过很多次,但是,所有提供的应该工作的示例今天似乎并不适合我。

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

“在服务 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"/>

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

I know this has been asked many times, and answered many times, but, all the provided samples that should be working don't seem to want to work for me today.

When I try to start the host, I keep getting the following error:

"The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service TraceService. Add a ServiceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract."

My service is being hosted in a managed windows service host as per Microsoft's example: http://msdn.microsoft.com/en-us/library/ms733069%28v=vs.90%29.aspx

And here is my nice and simple config:

  <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>

Of course, the problem becomes more interesting when there are no errors if I remove this line:

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

Any help would be very very very greatly appreciated :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最冷一天 2024-12-12 07:20:55

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

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

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

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

Be sure to specify a behaviorConfiguration in the service element of your configuration in order to allow either httpGet or httpsGet.

I see that you have already defined a serviceBehavior named DefaultBehavior - now all you need to do is add behaviorConfiguration="DefaultBehavior" to the service element, so that line becomes:

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

If you don't explicitly specify a behavior for your service, both HTTP GETs and HTTPS GETs are disallowed by default, and your metadata will not be exposed.

孤城病女 2024-12-12 07:20:55

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

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

并将基地址更改为 https 基地址。

或者(相反)将您的 wsHttp 绑定转换为 basicHttp 绑定,事情就会开始为您工作。

As you're using WS-Http you are binding to an HTTPS protocol, so you need to use the correct MEX binding;

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

and change the baseaddress to a https one.

Or (the other way around) convert your wsHttp binding to a basicHttp binding and things will start working for you.

情话难免假 2024-12-12 07:20:55
`<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
`<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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文