WCF中的IMetadataExchange问​​题

Geo*_*ge2 2 .net c# wcf visual-studio-2010

我正在使用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中找不到协议名称"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>
Run Code Online (Sandbox Code Playgroud)

rau*_*uts 5

您能否详细介绍一下您配置服务的方式.

http://msdn.microsoft.com/en-us/library/ms734765.aspx

这个链接有步骤.第5点和第6点应该是您感兴趣的.

帕文

尝试将此添加到Config文件的行为:

<behaviors>
      <serviceBehaviors>
        <behavior name="CalculatorServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
Run Code Online (Sandbox Code Playgroud)

并更改服务元素以添加此行为:

<service 
          name="Microsoft.ServiceModel.Samples.CalculatorService"
          behaviorConfiguration="CalculatorServiceBehavior">
Run Code Online (Sandbox Code Playgroud)

问候,

帕文