无法添加服务。可能无法访问服务元数据。确保您的服务正在运行并公开元数据[回复]

时间:2017-04-12 11:05:06

标签: web-services wcf

我编写简单的WCF Web服务(应用程序)。 我有错误:无法添加服务。可能无法访问服务元数据。确保您的服务正在运行并公开元数据。 请帮帮我。

我的网络服务:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using WCF;

namespace ValyutaService
{
    public class ValyutaService : IValyutaService
    {
        List<string> IValyutaService.ParaBirimleriniGetir()
        {
            List<String> paraBirimleri = new List<string>();
            paraBirimleri.Add("AZN");
            paraBirimleri.Add("USD");
            paraBirimleri.Add("EURO");
            paraBirimleri.Add("TL");
            paraBirimleri.Add("RUBL");
            return paraBirimleri;
        }

        public List<double> KurlariGetir(string kurTipi)
        {
            Random randomKur = new Random();
            ist<Double> kurlarListesi = new List<Double>();
            for (int i = 0; i < 15; i++)
            {
                kurlarListesi.Add(randomKur.NextDouble() + 2);
            }
            return kurlarListesi;
        }
    }
}

接口:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WCF
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IValyutaService
    {

        [OperationContract]
        List<string> ParaBirimleriniGetir();

        [OperationContract]
        List<Double> KurlariGetir(string kurTipi);
    }



}

Web配置:

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

0 个答案:

没有答案