title: Why won't my WCF service return an integer?
body: <p>I wrote a WCF service that reads data from my SQL Server database. It works fine when a call a method that returns all strings, but if I call a method that returns an int it crashes with some error about a timeout and too much data, which doesn't make sense to me...</p>
  
  <p>Here is my web service code:</p>
  
  <pre><code>public List&lt;Track&gt; getTrack()
  {
      List&lt;Track&gt; trackList = new List&lt;Track&gt;();
  
      SqlConnection dbConn = connectToDb();
  
      string _selectQuery = string.Format("SELECT Date, Track, KeyID FROM hdData ORDER BY Track");
  
      try
      {
          dbConn.Open();
          SqlCommand cmd = new SqlCommand(_selectQuery, dbConn);
          SqlDataReader reader = cmd.ExecuteReader();
  
          while (reader.Read())
          {
              Track Dat = new Track();
              Dat.Date = (string)reader[0];
              Dat.TrackName = (string)reader[1];
              Dat.KeyId = (int)reader[2];
              trackList.Add(Dat);
          }
  
          dbConn.Close();
       }
       catch (Exception e)
       {
          Console.WriteLine(e.ToString());
       }
  
       return trackList;
    }
  </code></pre>
  
  <p>If I take out the <code>KeyId</code> field it works fine... <code>KeyId</code> in the database is defined as a type <code>int</code> and is an auto incrementing field. </p>
  
  <p>I even tried casting it to a <code>varchar</code> but same result...</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Regards,
  Dean</p>
  
  <p>The exact error and Track class is as follows:</p>
  
  <p>Ok, exact error is:</p>
  
  <blockquote>
    <p>The maximum message size quota for incoming messages (65536) has been
    exceeded. To increase the quota, use the MaxReceivedMessageSize
    property on the appropriate binding element.</p>
    
    <p>Server stack trace:<br>
    at System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded()<br>
    at System.ServiceModel.Channels.HttpInput.GetMessageBuffer()<br>
    at System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream
    inputStream)<br>
    at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception&amp;
    requestException)<br>
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)<br>
    at System.ServiceModel.Channels.RequestChannel.Request(Message message,
    TimeSpan timeout)<br>
    at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message
    message, TimeSpan timeout)<br>
    at System.ServiceModel.Channels.ServiceChannel.Call(String action,
    Boolean oneway, ProxyOperationRuntime operation, Object[] ins,
    Object[] outs, TimeSpan timeout)<br>
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
    methodCall, ProxyOperationRuntime operation)<br>
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
    message)</p>
    
    <p>Exception rethrown at [0]:<br>
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
    reqMsg, IMessage retMsg)<br>
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp;
    msgData, Int32 type)<br>
    at IService1.getTrack()<br>
    at Service1Client.getTrack()</p>
    
    <p>Inner Exception:<br>
    The maximum message size quota for incoming messages
    (65536) has been exceeded. To increase the quota, use the
    MaxReceivedMessageSize property on the appropriate binding element.</p>
  </blockquote>
  
  <p>And the Track class is:</p>
  
  <pre><code>[DataContract]
  public class Track
  {
      string _Date, _TrackName;
      int _KeyId;
  
      [DataMember]
      public string Date
      {
          get { return _Date; }
          set { _Date = value; }
      }
  
      [DataMember]
      public string TrackName
      {
          get { return _TrackName; }
          set { _TrackName = value; }
      }
  
      [DataMember]
      public int KeyId
      {
          get { return _KeyId; }
          set { _KeyId = value; }
      }
  
  }
  </code></pre>