尝试通过添加服务引用时,无法在mvc5应用程序中使用WCF服务

时间:2016-12-19 09:00:41

标签: c# web-services wcf

您好我正在使用WCF,MVC4和angularJS开发小型应用程序。我正在推荐以下网址

https://code.msdn.microsoft.com/AngularJS-Shopping-Cart-8d4dde90#content

当我尝试在我的mvc应用程序中添加服务引用时,我收到以下错误

Metadata publishing for this service is currently disabled.

我在下方提供了访问服务的网址。

http://localhost:55835/Service1.svc

当我尝试时,我收到错误。我无法在我的应用程序中添加服务引用。我有点担心我的web.config文件。这是我的web.config文件。

<system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
    </httpModules>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors> 
        <behavior> 
          <webHttp helpEnabled="True"/> 
        </behavior> 
      </endpointBehaviors> 
    </behaviors>
    <protocolMapping>
      <add binding="webHttpBinding" scheme="http" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

有人能告诉我一些我在配置文件中缺少的东西吗?

提前谢谢。

1 个答案:

答案 0 :(得分:0)

显示此问题是因为您未启用metadata.Metadata(您的服务代码的wsdl文档)是必需的,因为您的客户端将根据您的元数据(wsdl代码)生成代理类。如果您不启用元数据,那么您的客户端将永远不知道如何在其代理类中实现相同类型的代码。这可以通过将httpGetEnabled设置为true来在servicebehavior标记下的servicemetadata标记下启用。

</endpointBehaviors>标记之后的servicebehavior标记下添加此行代码。(请不要再包含<behaviour>标记)

<behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->

          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" httpGetUrl="true"/>

        </behavior>
      </serviceBehaviors>
    </behaviors>
相关问题