我只是应用本文中的代码,
http://msdn.microsoft.com/en-us/library/ms733766(v=vs.110).aspx
我没有改变任何东西,但从 IIS 浏览后我得到
The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service CalculatorService. Add a ServiceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract
可能有什么问题,我只是按照链接做的。我寻找答案。我可以通过添加处理
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
但我不想添加这个,因为查看链接时 msdn 没有添加。错误是什么?
这是我的配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="Microsoft.ServiceModel.Samples.CalculatorService">
<!-- This endpoint is exposed at the base address provided by host: http://localhost/servicemodelsamples/service.svc -->
<endpoint address=""
binding="wsHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
<!-- The mex endpoint is explosed at http://localhost/servicemodelsamples/service.svc/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
最佳答案
我找不到任何说明 <serviceMetadata>
和 IMetadataExchange
之间关系的官方文件。
<serviceMetadata>
示例中的注释如下:
<!-- the mex endpoint is exposed at http://localhost/servicemodelsamples/service.svc/mex
To expose the IMetadataExchange contract, you
must enable the serviceMetadata behavior as demonstrated below -->
它说“你必须”,但还没有引用。
关于c# - WCF,找不到合约名称 'IMetadataExchange',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24874859/