0

私はWCFサービスを書いています。私のコードは

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ファイルはこのようなものです

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

しかし、このコードを実行すると、サービスの追加に失敗しましたというエラーが表示されます。サービス メタデータにアクセスできない場合があります。サービスが実行中で、メタデータを公開していることを確認してください。

エラーの詳細: エラー: RestServiceImpl.svc からメタデータを取得できません。これが Windows (R) Communication Foundation サービスにアクセスできる場合は、指定されたアドレスでのメタデータ公開が有効になっていることを確認してください。

4

1 に答える 1

0

web.config にエンドポイントのアドレスがないためです。

<endpoint address ="" binding="webHttpBinding" 
          contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
于 2012-10-02T05:54:56.930 に答える