wcf传输大于5021条数据报错,在小于5021条数据没有问题,
服务端配置
<bindings>
      <netTcpBinding>
        <binding name="TcpBinding" closeTimeout="00:02:30" sendTimeout="00:05:00"
          maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="64" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="65536" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
客户端配置:
string urilogin = "net.tcp://" + PubPara.SvrIP + ":919/Z_RCheck.Service/ServiceQuery/";
            Uri uri1 = new Uri(urilogin);
            EndpointAddress ep = new EndpointAddress(uri1);
            NetTcpBinding bing = new NetTcpBinding();
            bing.MaxReceivedMessageSize = Int32.MaxValue;
            bing.MaxBufferSize = Int32.MaxValue;
            TimeSpan ts=new TimeSpan(0,5,0);
            bing.SendTimeout = ts;
            bing.Security.Mode = SecurityMode.None;
            XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas();
            //readerQuotas.MaxArrayLength = 25 * 1024;
            readerQuotas.MaxArrayLength = 2147483647;
            readerQuotas.MaxStringContentLength = 2147483647;
            readerQuotas.MaxDepth = 64;
            readerQuotas.MaxBytesPerRead = 65536;
            readerQuotas.MaxNameTableCharCount = 2147483647;
            bing.ReaderQuotas = readerQuotas;
            mServiceQuery = ChannelFactory<IServiceQuery>.CreateChannel(bing, ep);
错误提示:如下
未处理 System.ServiceModel.CommunicationException
  Message=套接字连接已中止。这可能是由于处理消息时出错或远程主机超过接收超时或者潜在的网络资源问题导致的。本地套接字超时是“00:05:00”。
  Source=mscorlib
  StackTrace:
    Server stack trace: 
       在 System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
       在 System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
       在 System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
       在 System.ServiceModel.Channels.SessionConnectionReader.Receive(TimeSpan timeout)
       在 System.ServiceModel.Channels.SynchronizedMessageSource.Receive(TimeSpan timeout)
       在 System.ServiceModel.Channels.FramingDuplexSessionChannel.Receive(TimeSpan timeout)
       在 System.ServiceModel.Channels.FramingDuplexSessionChannel.TryReceive(TimeSpan timeout, Message& message)
       在 System.ServiceModel.Dispatcher.DuplexChannelBinder.Request(Message message, TimeSpan timeout)
       在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
       在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Exception rethrown at [0]: 
       在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       在 Z_RCheck.IService.IServiceQuery.GetQuery_KSAnnalLook(String LXcode, DateTime JDdateStart, DateTime JDdateEnd, String Oname, String TEL)
       在 Z_RCheck.Client.Frm.R_Frm_Query_KSAnnalLook.SelectFill() 位置 D:\Z_RCheck\Z_RCheck.Client\Frm\R_Frm_Query_KSAnnalLook.cs:行号 54
       在 Z_RCheck.Client.Frm.R_Frm_Query_KSAnnalLook.toolStripbtnLook_Click(Object sender, EventArgs e) 位置 D:\Z_RCheck\Z_RCheck.Client\Frm\R_Frm_Query_KSAnnalLook.cs:行号 43
       在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
       在 System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
       在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
       在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
       在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
       在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
       在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.RunDialog(Form form)
       在 System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
       在 System.Windows.Forms.Form.ShowDialog()
       在 Z_RCheck.Client.Frm.R_Frm_Main.btnIQuery_KSAnnalLook_Click(Object sender, EventArgs e) 位置 D:\Z_RCheck\Z_RCheck.Client\Frm\R_Frm_Main.cs:行号 1516
       在 DevComponents.DotNetBar.BaseItem.RaiseClick(eEventSource source)
       在 DevComponents.DotNetBar.BaseItem.InternalMouseUp(MouseEventArgs objArg)
       在 DevComponents.DotNetBar.PopupItem.InternalMouseUp(MouseEventArgs objArg)
       在 DevComponents.DotNetBar.ButtonItem.InternalMouseUp(MouseEventArgs objArg)
       在 DevComponents.DotNetBar.BaseItem.InternalMouseUp(MouseEventArgs objArg)
       在 DevComponents.DotNetBar.SideBarPanelItem.InternalMouseUp(MouseEventArgs objArg)
       在 DevComponents.DotNetBar.BaseItem.InternalMouseUp(MouseEventArgs objArg)
       在 DevComponents.DotNetBar.SideBar.OnMouseUp(MouseEventArgs e)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 DevComponents.DotNetBar.SideBar.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 Z_RCheck.Client.Program.Main() 位置 D:\Z_RCheck\Z_RCheck.Client\Program.cs:行号 95
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Net.Sockets.SocketException
       Message=远程主机强迫关闭了一个现有的连接。
       Source=System
       ErrorCode=10054
       NativeErrorCode=10054
       StackTrace:
            在 System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
            在 System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
       InnerException: 

解决方案 »

  1.   

    客户端加这个看看bind.MaxBufferPoolSize = Int32.MaxValue;
    maxBufferPoolSize
    maxReceivedMessageSize
    maxArrayLength
    这三个属性是都要设置的
    也可能是sendTimeout时间内没有发送完成
      

  2.   

                bind.MaxReceivedMessageSize = Int32.MaxValue;
                bind.MaxBufferPoolSize = Int32.MaxValue;
                bind.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
      

  3.   

    推测内部异常是 MaxItemsInObjectGraph 的限制参考:http://blog.csdn.net/fangxinggood/article/details/6031072
      

  4.   

    sendTimeout我设置了5分钟,程序运行到30多秒就报错提示了
      

  5.   

    服务端
    <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <serviceMetadata httpGetEnabled="false" />
              <serviceDebug httpHelpPageEnabled="false" includeExceptionDetailInFaults="false" />
              <dataContractSerializer maxItemsInObjectGraph="65536"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>maxItemsInObjectGraph="65536"
      

  6.   

    readerQuotas.MaxBytesPerRead = 65536; 设大点
      

  7.   

    客户端
    string urilogin = "net.tcp://" + PubPara.SvrIP + ":921/Z_RCheck.Service/ServiceTel/";
                Uri uri1 = new Uri(urilogin);
                EndpointAddress ep = new EndpointAddress(uri1);
                NetTcpBinding bing = new NetTcpBinding();
                bing.MaxBufferSize = Int32.MaxValue;
                bing.MaxBufferPoolSize = Int32.MaxValue;
                bing.MaxReceivedMessageSize = Int32.MaxValue;
                TimeSpan ts = new TimeSpan(0, 5, 0);
                bing.SendTimeout = ts;
                bing.Security.Mode = SecurityMode.None;
                XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas();
                readerQuotas.MaxArrayLength = 2147483647;
                readerQuotas.MaxStringContentLength = 2147483647;
                readerQuotas.MaxDepth = 64;
                readerQuotas.MaxBytesPerRead = 2147483647;
                readerQuotas.MaxNameTableCharCount = 2147483647;
                bing.ReaderQuotas = readerQuotas;
                mServiceTel = ChannelFactory<IServiceTel>.CreateChannel(bing, ep);
    服务端
    <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <serviceMetadata httpGetEnabled="false" />
              <serviceDebug httpHelpPageEnabled="false" includeExceptionDetailInFaults="false" />
              <dataContractSerializer maxItemsInObjectGraph="65536"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <bindings>
          <netTcpBinding>
            <binding name="TcpBinding" closeTimeout="00:02:30" sendTimeout="00:05:00"
              maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="64" maxStringContentLength="2147483647"
                maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
              <security mode="None">
                <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                <message clientCredentialType="Windows" />
              </security>
            </binding>
          </netTcpBinding>
        </bindings>
      

  8.   

    请问:fangxinggood 
    怎么在客户端使用代码方式配置:
    dataContractSerializer maxItemsInObjectGraph="XXXXXXXXXXXXX"/
      

  9.   

    <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      

  10.   

    问题解决了,感谢:方兴
    就是因为:服务端和客户端的
    MaxItemsInObjectGraph=65536;值太小的问题