【问题标题】:Unable to consume WCF service in mvc5 application when trying to get through add service reference尝试通过添加服务引用时无法在 mvc5 应用程序中使用 WCF 服务
【发布时间】:2016-12-19 09:00:40
【问题描述】:

您好,我正在使用 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>

有人能告诉我我在配置文件中遗漏了什么吗?

提前谢谢你。

【问题讨论】:

  • &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/&gt; 行为添加到您的配置文件中。

标签: c# web-services wcf


【解决方案1】:

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

&lt;/endpointBehaviors&gt;标签之后的servicebehavior标签下添加这行代码。(请不要再次包含&lt;behaviour&gt;标签)

<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-11
    • 2014-05-08
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多