C# 为什么赢了';我的WCF服务是否返回整数?

C# 为什么赢了';我的WCF服务是否返回整数?,c#,wcf,C#,Wcf,我编写了一个WCF服务,从我的SQL Server数据库读取数据。当调用一个返回所有字符串的方法时,它可以正常工作,但如果我调用一个返回int的方法,它会崩溃,并出现超时错误和太多数据,这对我来说没有意义 以下是我的web服务代码: public List<Track> getTrack() { List<Track> trackList = new List<Track>(); SqlConnection dbConn = connectT

我编写了一个WCF服务,从我的SQL Server数据库读取数据。当调用一个返回所有字符串的方法时,它可以正常工作,但如果我调用一个返回int的方法,它会崩溃,并出现超时错误和太多数据,这对我来说没有意义

以下是我的web服务代码:

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;
  }
当你说“如果我把KeyId字段去掉”时,你的意思是从田径课上移除吗?如果是这样,您返回的曲目列表的大小是否可能接近端点绑定MaxReceivedMessageSize(65536)?如果是这种情况,则通过从Track类中删除_keyidint来减小该列表的大小可能会将返回的总数据大小减小到该限制以下。
尝试在端点绑定中增加此限制。您可能需要同时为服务器和客户端执行此操作。例如:

 maxBufferPoolSize="10000000" maxBufferSize="10000000" maxReceivedMessageSize="10000000">
    <readerQuotas maxDepth="32"
        maxStringContentLength="10000000" maxArrayLength="10000000"
        maxBytesPerRead="10000000" maxNameTableCharCount="10000000" />
maxBufferPoolSize=“10000000”maxBufferSize=“10000000”maxReceivedMessageSize=“10000000”>

基本上,您需要增加邮件的大小。为此,您需要为正在使用的任何绑定创建一个绑定配置——这里我使用
basicHttpBinding
作为示例。因此,您需要定义绑定配置(在服务器和客户端的配置中),并且您的服务以及客户端都需要引用该绑定配置:

<system.serviceModel>
  <bindings>
    <!-- use whichever binding you're using here! -->
    <basicHttpBinding>
      <!-- define a binding configuration with a name -->
      <binding name="LargeData"
               maxBufferSize="999999" maxReceivedMessageSize="999999" />
    </basicHttpBinding>
  </bindings>
  <services>
    <service name="Namespace.YourServiceClass">
      <!-- your endpoints - both on the server as well as on the client - need
           to make reference to that defined binding configuration -->
      <endpoint name="test"
                address="...."
                binding="basicHttpBinding"
                bindingConfiguration="LargeData"
                contract="Namespace.IYourServiceContract" />
    </service>
  </services>
</system.serviceModel>

在客户机上,您将看到:

   <client name="....">
        <endpoint name="test"
            address="...."
            binding="basicHttpBinding"
            bindingConfiguration="LargeData"
            contract="Namespace.IYourServiceContract" />
   </client>   

我期待配额错误,这就是为什么我问你确切的错误消息

请仔细阅读此链接: 特别是配额部分(但我认为整篇文章将帮助您更好地了解WCF)


然后,请不要忘记,您还必须在客户端更改这些设置(配额)(即更新服务器后刷新web引用)

您能告诉我们确切的错误吗?还有田径课。您还应该关闭读卡器。如果您使用MsSql CE数据库,您的密钥ID可能不是int而是GUID。然后在尝试转换为int时出现错误。启用以查看详细的错误消息并向我们显示该错误。Boom发布了错误,现在一切都已清除-在endpoint中增加
MaxReceivedMessageSize
。我已在我的web.config中增加MaxReceivedMessageSize。现在的问题是,当我将它发布到我的web主机(www.winhost.com)时,它似乎没有生效。我假设web主机会使用我发布的任何web.config文件?这是另一个问题。我不能真的帮助你,因为我只有经验,在赢服务托管而不是IIS托管的WCF服务器。你最好把它作为一个单独的问题发布。好的,谢谢你,鲍勃,我会先把它发送给winhost团队,看看他们是否能回答。顺便说一句,这个问题刚刚出现-它可能会帮助你(直接用它包含的信息或者当它被回答时)整理好,谢谢大家。。。都在web.config文件中:)
   <client name="....">
        <endpoint name="test"
            address="...."
            binding="basicHttpBinding"
            bindingConfiguration="LargeData"
            contract="Namespace.IYourServiceContract" />
   </client>