我正在使用 VSTS 2010 + C# + .Net 4.0 + IIS 7.5 + Windows 7。我遵循此处的 MSDN 示例,没有任何修改,http://msdn.microsoft.com/en-us/library/ms733766.aspx
当我在 IIS 中打开 service.svc 文件(在 IIS 管理器中,右键单击 svc 文件并选择浏览)时,出现这样的错误,您知道出了什么问题吗?
在服务列表CalculatorService 中找不到协议(protocol)名称“IMetadataExchange”。在配置文件中添加ServiceMetadataBehavior或者直接添加到ServiceHost
这是我正在使用的 web.config,
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<!-- This section is optional with the default configuration
model introduced in .NET Framework 4 -->
<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 exposed at http://localhost/servicemodelsamples/service.svc/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
最佳答案
您能否提供一些有关您配置服务的方式的详细信息。
http://msdn.microsoft.com/en-us/library/ms734765.aspx
此链接包含步骤。第 5 点和第 6 点应该是您感兴趣的。
帕万
尝试将此行为添加到配置文件:
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
并更改服务元素以添加此行为:
<service
name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
问候,
帕范
关于c# - WCF 中的 IMetadataExchange 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3788726/