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

查看:187
本文介绍了无法添加服务。服务元数据可能无法访问。确保你的服务正在运行和公开元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写WCF服务。我的code是

I am writing WCF Service. My code is

namespace RestService
{
    public class user
    {
        public user(string i, string b, string l)
        {
            id = i;
            badgeNumber = b;
            login = l;
        }

        public string id { get; set; }
        public string badgeNumber { get; set; }
        public string login { get; set; }
    }

    public class RestServiceImpl : IRestServiceImpl
    {
        #region IRestServiceImpl Members

        public string XMLData(string id)
        {
            return "You requested product " + id;
        }

        public user[] JSONData(string id)
        {
            OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\confiz\Desktop\att2000.mdb");
            connection.Open();
            OleDbCommand command = new OleDbCommand("SELECT count(*) FROM USERINFO", connection);
            int users_count = (int)command.ExecuteScalar();

            command = new OleDbCommand("SELECT * FROM USERINFO", connection);
            OleDbDataReader reader = command.ExecuteReader();
         //   string jsonString = "";
            user[] users = new user[users_count];

            int i=0;
            while (reader.Read())
            {
                users[i].id = reader["USERID"].ToString();
                users[i].badgeNumber = reader["Badgenumber"].ToString();
                users[i].login = reader["SSN"].ToString();

             /*   user = new user(reader["USERID"].ToString(), reader["Badgenumber"].ToString(), reader["SSN"].ToString());
                System.Web.Script.Serialization.JavaScriptSerializer jsSerializer;
                jsSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                System.Text.StringBuilder sbUser = new System.Text.StringBuilder();
                jsSerializer.Serialize(user, sbUser);
                string json = sbUser.ToString();
                */
           //     jsonString = jsonString + json;

                i++;
            }
            connection.Close();
            return users;
        }

        #endregion
    }
}

我的web.config文件是这样的

My Web.config file is like this

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

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address ="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
        </endpoint>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="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>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

但是当我运行此$ C C I得到错误
无法添加服务。服务元数据可能无法访问。确保你的服务正在运行,揭露元数据。

but when i run this code i get error Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.

错误详细信息:错误:无法从RestServiceImpl.svc获得元数据如果这是Windows(R)通信基础服务,您有权访问,请检查您是否已经启用元数据发布在指定的地址。

Error Details: Error: Cannot obtain Metadata from RestServiceImpl.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.

推荐答案

我会说,那是因为你没有一个地址在web.config您的端点。

I'm going to say it's because you don't have an address for your endpoint in the web.config.

<endpoint address ="" binding="webHttpBinding" 
          contract="RestService.IRestServiceImpl" behaviorConfiguration="web">

这篇关于无法添加服务。服务元数据可能无法访问。确保你的服务正在运行和公开元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆