title: Console Application Failed to Retrieve Data With Wcf Service
body: <p>I am consuming wcf service into console application . I am trying to retrieve account information based on account number . But the problem is when i enter the account number and hit enter ,its only displaying account number and rest of the fields are empty.</p>
  
  <p>Here is the base class.</p>
  
  <pre><code>[DataContract]
      public class Current_Account_Details
      { 
      string account_creation_date;
      string account_type;
      string branch_sort_code;
      string account_fees;
      string account_balance;
      string over_draft_limit;
      string  account_holder_id;
  
      [DataMember]
      public string Account_Creation_Date
      {
          get { return account_creation_date; }
          set { account_creation_date = value; }
      }
      [DataMember]
      public string Account_Type
      {
          get { return account_type; }
          set { account_type = value; }
      }
      [DataMember]
      public string Branch_Sort_Code
      {
          get { return branch_sort_code; }
          set { branch_sort_code = value; }
      }
      [DataMember]
      public string Account_Fees
      {
          get { return account_fees; }
          set { account_fees = value; }
  
      }
      [DataMember]
      public string Account_Balance
      {
          get { return account_balance; }
          set { account_balance = value; }
  
  
      }
      [DataMember]
      public string Over_Draft_Limit
      {
  
          get { return over_draft_limit; }
          set { over_draft_limit = value; }
  
      }
      [DataMember]
      public string Account_Holder_Id
      {
  
          get { return account_holder_id; }
          set { account_holder_id = value; }
      }
  }
  }
  </code></pre>
  
  <p>Here is the inherited class.</p>
  
  <pre><code> [DataContract]
      public class AccountBalanceRequest : Current_Account_Details
      {
          string account_number;
  
          [DataMember]
          public string Account_Number
          {
              get { return account_number; }
              set { account_number = value; }
          }
      }
  }
  </code></pre>
  
  <p>Here is the Interface .</p>
  
  <pre><code> [OperationContract]
          AccountBalanceRequest AccountBalanceCheek(AccountBalanceRequest accountNumber);
  </code></pre>
  
  <p>Here is my Method .</p>
  
  <pre><code>public AccountBalanceRequest AccountBalanceCheek(AccountBalanceRequest accountNumber)
      {
          using (SqlConnection conn = new SqlConnection(ConnectionString))
          {
              conn.Open();
              //use top 1 since you are only getting one record.
              //let us use string interpolation, if you are working below C#6
              //replace it with your previous value
              var cmd = new SqlCommand($@"SELECT TOP 1
                                              * 
                                          FROM 
                                              Current_Account_Details 
                                          WHERE 
                                              Account_Number ='{accountNumber.Account_Number}'", conn);
              cmd.CommandType = CommandType.Text;
              //use ExecuteReader to execute sql select
              //ExecuteNonQuery is for update, delete, and insert.
              var reader = cmd.ExecuteReader();
              //read the result of the execute command.
              while (reader.Read())
              {
                  //assuming that your property is the same as your table schema. refer to your table schema Current_Account_Details
                  //assuming that your datatype are string... just do the conversion...
                  accountNumber.Account_Balance = reader["Account_Balance"].ToString();
                  accountNumber.Account_Fees = reader["Account_Fees"].ToString();
                  accountNumber.Account_Balance = reader["Account_Balance"].ToString();
                  accountNumber.Over_Draft_Limit = reader["Over_Draft_Limit"].ToString();
              }
              return accountNumber;
          }
  
      }
  </code></pre>
  
  <p>Here is the code in Console Application .</p>
  
  <pre><code>     public static void Balance()
      {
          MyService.HalifaxCurrentAccountServiceClient currentAccount = new MyService.HalifaxCurrentAccountServiceClient("NetTcpBinding_IHalifaxCurrentAccountService");
          MyService.AccountBalanceRequest cs = new MyService.AccountBalanceRequest();
  
          string AccountNumber;
  
  
          Console.WriteLine("\nEnter your Account Number--------:");
          AccountNumber = Console.ReadLine();
          cs.Account_Number = AccountNumber;
          // MyService.AccountBalanceRequest cs1 = currentAccount.AccountBalanceCheek(AccountNumber);
  
  
  
          MyService.AccountBalanceRequest AccountBalance = currentAccount.AccountBalanceCheek(cs);//error on this line
  
                 Console.WriteLine("Account Number is :" + cs.Account_Number);
                  Console.WriteLine("Account creation date  :" + cs.Account_Creation_Date);
  
                  Console.WriteLine("Account Type :" + cs.Account_Type);
                  Console.WriteLine("Branch_Sort_Code:" + cs.Branch_Sort_Code);
                  Console.WriteLine("Account_Fee:" + cs.Account_Fees);
                  Console.WriteLine("Account Account_Balance :" + cs.Account_Balance);
                  Console.WriteLine("Account Over Draft Limit :" + cs.Over_Draft_Limit);
  
  
              Console.Write("--------------------------");
                  Console.ReadLine();
                  //Console.Clear();
  
  
         }
  </code></pre>
  
  <p>Here is the screen shot of the database.<a href="https://i.stack.imgur.com/vGugZ.png" rel="nofollow noreferrer">click here to record</a>
  Here is the screen shot when i run the application<a href="https://i.stack.imgur.com/jtMuu.png" rel="nofollow noreferrer">Click here to see the result</a>.<strong>In this screen shot only the account number is displaying and rest of the fields are empty</strong> </p>