WCF元数据未显示

时间:2015-10-14 10:49:16

标签: c# wcf iis

我已经跟着this tutorial信了,但是在导航到服务地址(http://localhost/IISHostedCalc/Service.svc后)后,我找到了一个以下面的消息开头的页面:

  

此服务的元数据发布目前已停用。

在页面底部有关于如何启用元数据发布但没有成功的说明 我还试图实施thisthis,但它没有用。

这就是我的服务的样子:
C:\ IISHostedCalcService \ service.svc:

<%@ServiceHost language=c# Debug="true" Service="Microsoft.ServiceModel.Samples.CalculatorService"%>

C:\ IISHostedCalcService \ App_Code文件\ Service.cs:

using System;
using System.ServiceModel;

namespace Microsoft.ServiceModel.Samples
{
  [ServiceContract]
  public interface ICalculator
  {
     [OperationContract]
     double Add(double n1, double n2);
     [OperationContract]
     double Subtract(double n1, double n2);
     [OperationContract]
     double Multiply(double n1, double n2);
     [OperationContract]
     double Divide(double n1, double n2);
  }

  public class CalculatorService : ICalculator
  {
     public double Add(double n1, double n2)
     {
        return n1 + n2;
     }
     public double Subtract(double n1, double n2)
     {
        return n1 - n2;
     }
     public double Multiply(double n1, double n2)
     {
        return n1 * n2;
     }
     public double Divide(double n1, double n2)
     {
        return n1 / n2;
     }
  } 
}

C:\ IISHostedCalcService \ App_Code文件\的Web.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="Microsoft.ServiceModel.Samples.CalculatorService"
      behaviorConfiguration="SimpleServiceBehavior">
        <endpoint address=""
                  binding="wsHttpBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />

        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="SimpleServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

IIS版本为7.5: iis

我的web.config文件是否可能被忽略(或者至少是其中的一部分)或者是其他东西?
编辑我完全从app_code文件夹中删除了web.config文件,但仍然到达了完全相同的页面,因此我猜我的web.config被忽略了。有什么方法可以解决吗?

1 个答案:

答案 0 :(得分:0)

问题可能是Web.config位置。

尝试将.svc文件和web.config文件放在同一文件夹中,这就是配置正确但未应用的原因。