简体   繁体   English

WCF:无法添加服务。 服务元数据可能无法访问

[英]WCF:Failed to add a service. Service metadata may not be accessible

I have searched this question , and got too many links ,and tried most of them , but my problem is not solved . 我已经搜索了这个问题,并获得了太多的链接,并尝试了大多数链接,但是我的问题没有解决。 I'm running my VS in admin mode. 我在管理员模式下运行VS。 I created new project then add WCF service to my project .I want to call my service through ajax. 我创建了一个新项目,然后将WCF服务添加到我的项目中。我想通过ajax调用我的服务。

this is my code in Sevice.cs and Iservice.cs 这是我在Sevice.cs和Iservice.cs中的代码

namespace WcfWithAjax
{
    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
        string GetEmployeeList();
    }
}

and

namespace WcfWithAjax
{

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service : IService
    {
        [OperationContract]

        public string GetEmployeeList()
        {
            string str = ConfigurationManager.ConnectionStrings["connect"].ConnectionString;
            IList<Employee> employeeList = new List<Employee>();
            using (SqlConnection con = new SqlConnection(str))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("select * from Employee", con);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    employeeList.Add(new Employee()
                    {
                        Id = dr.GetInt32(0),
                        Name = dr.GetString(1),
                        Position = dr.GetString(2),
                        Age = dr.GetInt32(3),
                        Salary = dr.GetInt32(4)
                    });
                }
                con.Close();
            }
            JavaScriptSerializer objJson = new JavaScriptSerializer();
            return objJson.Serialize(employeeList);
        }

    }
}

and then configured my web.config file as follow 然后将我的web.config文件配置如下

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metadataBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>

    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    <services>
      <service name="WcfWithAjax.Service" behaviorConfiguration="metadataBehavior">
        <endpoint address=""  binding="webHttpBinding" contract="WcfWithAjax.IService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
  </system.serviceModel>

now I'm Debuging my project but it's showing 现在我正在调试我的项目,但它正在显示

Failed to add a service. 添加服务失败。 Service metadata may not be accessible. 服务元数据可能无法访问。 Make sure your service is running and exposing metadata . 确保您的服务正在运行并公开元数据

Here is some link i got but unable to solve my problem 这是我得到的但无法解决我的问题的一些链接

failed-to-add-a-service-service-metadata-may-not-be-accessible-make-sure-your 未能对添加一种服务,服务元数据可以-不被访问的,化妆肯定,你的

Link 2 连结2

Change you config code ad follow 更改您的配置代码广告

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metadataBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="ServiceAspNetAjaxBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
      <service name="WcfWithAjax.Service" behaviorConfiguration="metadataBehavior">
        <endpoint address=""  binding="webHttpBinding" contract="WcfWithAjax.IService" behaviorConfiguration="ServiceAspNetAjaxBehavior"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
  </system.serviceModel>

暂无
暂无

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

相关问题 运行WCF服务获取错误添加服务失败。 服务元数据可能无法访问 - Run WCF service getting error Failed to add a service. Service metadata may not be accessible 添加服务失败。 服务元数据可能无法访问 - Failed to add a service. Service metadata may not be accessible 获取&#39;无法添加服务。 服务元数据可能无法访问。 测试 WCF 项目时出错 - Getting 'Failed to add a service. Service metadata may not be accessible.' error when testing a WCF project WcfTestClient:添加服务失败。 服务元数据可能无法访问 - WcfTestClient: Failed to add a service. Service metadata may not be accessible WCF测试客户端:无法添加服务。可能无法访问服务元数据。确保您的服务正在运行并公开元数据 - WCF Test Client : Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata 添加服务失败。 服务元数据可能无法访问。 确保您的服务正在运行并公开元数据。 WCF错误 - Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata. WCF Error WCF:无法添加服务。 可能无法访问服务元数据。 确保您的服务正在运行并公开元数据 - WCF: Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata WCF无法添加服务。 可能无法访问服务元数据。 确保您的服务正在运行并公开元数据 - WCF Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata 添加服务失败。 服务元数据可能无法访问。 确保您的服务正在运行并公开元数据 - Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata 服务元数据可能无法在WCF中访问 - Service metadata may not be accessible In WCF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM