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…
Here is my web service code:
public List<Track> getTrack()
{
List<Track> trackList = new List<Track>();
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;
}
If I take out the KeyId field it works fine… KeyId in the database is defined as a type int and is an auto incrementing field.
I even tried casting it to a varchar but same result…
What am I doing wrong?
Regards,
Dean
The exact error and Track class is as follows:
Ok, exact error is:
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.Server stack trace:
at System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded()
at System.ServiceModel.Channels.HttpInput.GetMessageBuffer()
at System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream
inputStream)
at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception&
requestException)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message,
TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message
message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action,
Boolean oneway, ProxyOperationRuntime operation, Object[] ins,
Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
message)Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at IService1.getTrack()
at Service1Client.getTrack()Inner Exception:
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.
And the Track class is:
[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; }
}
}
When you say “If I take out the KeyId field” do you mean remove from Track class? If so is it possible that the size of your Track list you are returning is close to your endpoint bindings MaxReceivedMessageSize (65536)? If this was the case then reducing the size of that List by removing a the _KeyId int from the Track class may reduce the overall returned data size below this limit.
Try increasing this limit in the end point binding. You may need to do this for both server and client. Eg: