mexHttpBinding - 将 ServiceMetadataBehavior 添加到配置文件或直接添加到 ServiceHost 以启用对此合约的支持
我知道这个问题已经被问过很多次,也被回答过很多次,但是,所有提供的应该工作的示例今天似乎并不适合我。
当我尝试启动主机时,不断收到以下错误:
“在服务 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请务必在配置的
service
元素中指定behaviorConfiguration
,以便允许httpGet
或httpsGet
。我看到您已经定义了一个名为
DefaultBehavior
的 serviceBehavior - 现在您需要做的就是将behaviorConfiguration="DefaultBehavior"
添加到service
元素,因此该行变为:如果您没有显式指定服务的行为,则默认情况下不允许 HTTP GET 和 HTTPS GET,并且您的元数据将不会公开。
Be sure to specify a
behaviorConfiguration
in theservice
element of your configuration in order to allow eitherhttpGet
orhttpsGet
.I see that you have already defined a serviceBehavior named
DefaultBehavior
- now all you need to do is addbehaviorConfiguration="DefaultBehavior"
to theservice
element, so that line becomes: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.
当您使用 WS-Http 时,您将绑定到 HTTPS 协议,因此您需要使用正确的 MEX 绑定;
并将基地址更改为 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;
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.