简体   繁体   English

尝试获取添加服务引用时无法在Mvc5应用程序中使用WCF服务

[英]Unable to consume WCF service in mvc5 application when trying to get through add service reference

Hi I am developing small application using WCF,MVC4 and angularJS. 嗨,我正在使用WCF,MVC4和angularJS开发小型应用程序。 I am refering following URL 我指的是以下网址

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

When i tried to add service reference in my mvc application I am getting below error 当我尝试在我的MVC应用程序中添加服务引用时,出现以下错误

Metadata publishing for this service is currently disabled.

I gave below url to access service. 我在下面的网址中提供了访问服务。

http://localhost:55835/Service1.svc

When i tried I am getting error. 当我尝试时,我得到了错误。 I am unable to add service reference in my application. 我无法在应用程序中添加服务引用。 I am little worried about my web.config file. 我有点担心我的web.config文件。 This is my web.config file. 这是我的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>

Can someone tell me something I am missing anything in config file? 有人可以告诉我一些我在配置文件中缺少的东西吗?

Thank you in advance. 先感谢您。

This problem is displaying because you are not enabling metadata.Metadata(wsdl document for your service code) is neccessary because your client will generate proxy class on the basis of your metadata(wsdl code). 由于未启用元数据而出现此问题。由于客户端将基于元数据(wsdl代码)生成代理类,因此必须使用元数据(用于服务代码的wsdl文档)。 If you will not enable your metadata then your client will never know how to implement the same kind of code in its's proxy classes.And this can be enabled under servicemetadata tag under servicebehavior tag by setting httpGetEnabled to true. 如果不启用元数据,那么客户端将永远不会知道如何在其代理类中实现相同类型的代码。这可以通过将httpGetEnabled设置为true在servicebehavior标记下的servicemetadata标记下启用。

Add this line of code under servicebehavior tag just after </endpointBehaviors> tag.(please do not include <behaviour> tag again) </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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM