2011-09-20 86 views
1

:) 我有一个奇怪的问题。 我有一个自托管WCF服务,从数据库获取数据并发送到WPF客户端。读取大数据块时超时(但不是超时),但只有外部VS2010

现在,我遇到了“假超时问题”(“套接字连接重置,这可能是由处理消息的错误导致的,”......等),我解决了它纠正安全标签(它是“无“,我纠正为”运输“

当我执行VS2010环境(比如说,没有调试和WcfSvcHost,但有服务在MMC中运行并从Windows资源管理器执行该程序),我又去了相同的错误,这次只在从数据库读取大量数据时(比如25k行表)

这里是服务器App.config:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections></configSections> 
    <system.web> 
    <compilation debug="true" /> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service behaviorConfiguration="SvrBehavior" name="WCFSrvLib.WCFSrvLib"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:8732/WCFSrvLib"/> 
      <add baseAddress="http://localhost:802/WCFSrvLib/mex"/> 
      </baseAddresses> 
     </host> 
    <endpoint bindingConfiguration="tcpSvrBinding" binding="netTcpBinding" contract="PhXSrvLib.IPhXSrvLib" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
</services> 
<bindings> 
    <netTcpBinding> 
    <binding name="tcpSvrBinding" 
      closeTimeout="00:05:00" 
      openTimeout="00:05:00" 
      receiveTimeout="00:05:00" 
      sendTimeout="00:05:00" 
      transactionFlow="false" 
      transferMode="Buffered" 
      transactionProtocol="OleTransactions" 
      hostNameComparisonMode="StrongWildcard" 
      listenBacklog="10" 
      maxBufferPoolSize="2147483647" 
      maxBufferSize="2147483647" 
      maxConnections="10" 
      maxReceivedMessageSize="2147483647" 
      portSharingEnabled="true"> 

     <readerQuotas maxDepth="32" 
        maxStringContentLength="2147483647" 
        maxArrayLength="2147483647" 
        maxBytesPerRead="2147483647" 
        maxNameTableCharCount="2147483647" /> 

     <reliableSession ordered="true" 
         inactivityTimeout="00:10:00" 
         enabled="false" /> 

     <security mode="Transport"> 
     <transport clientCredentialType="Windows" /> 
     </security> 

    </binding> 
    </netTcpBinding> 
</bindings> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="SvrBehavior"> 
     <serviceThrottling maxConcurrentCalls="50" maxConcurrentSessions="10" maxConcurrentInstances="50"/> 
     <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
     <serviceMetadata httpGetEnabled="True" /> 
     <serviceDebug includeExceptionDetailInFaults="True" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

...这是代码片段,我创建的ChannelFactory,和消费服务

 ChannelFactory<IWCFSrvLib> cf = new ChannelFactory<IWCFSrvLib>(new NetTcpBinding()); 
     ((NetTcpBinding)cf.Endpoint.Binding).CloseTimeout = new TimeSpan(0, 5, 0); 
     ((NetTcpBinding)cf.Endpoint.Binding).OpenTimeout = new TimeSpan(0, 5, 0); 
     ((NetTcpBinding)cf.Endpoint.Binding).ReceiveTimeout = new TimeSpan(0, 5, 0); 
     ((NetTcpBinding)cf.Endpoint.Binding).SendTimeout = new TimeSpan(0, 5, 0); 
     ((NetTcpBinding)cf.Endpoint.Binding).TransactionFlow = false; 
     ((NetTcpBinding)cf.Endpoint.Binding).TransferMode = TransferMode.Buffered; 
     ((NetTcpBinding)cf.Endpoint.Binding).TransactionProtocol = TransactionProtocol.OleTransactions; 
     ((NetTcpBinding)cf.Endpoint.Binding).MaxReceivedMessageSize = Int32.MaxValue; 
     ((NetTcpBinding)cf.Endpoint.Binding).MaxConnections = 10; 
     ((NetTcpBinding)cf.Endpoint.Binding).MaxBufferPoolSize = Int32.MaxValue; 
     ((NetTcpBinding)cf.Endpoint.Binding).MaxBufferSize = Int32.MaxValue; 
     ((NetTcpBinding)cf.Endpoint.Binding).Security.Mode = SecurityMode.Transport; 
     ((NetTcpBinding)cf.Endpoint.Binding).Security.Message.ClientCredentialType = MessageCredentialType.Windows; 
     ((NetTcpBinding)cf.Endpoint.Binding).ReaderQuotas.MaxArrayLength = Int32.MaxValue; 
     ((NetTcpBinding)cf.Endpoint.Binding).ReaderQuotas.MaxBytesPerRead = Int32.MaxValue; 
     ((NetTcpBinding)cf.Endpoint.Binding).ReaderQuotas.MaxDepth = 32; 
     ((NetTcpBinding)cf.Endpoint.Binding).ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue; 
     ((NetTcpBinding)cf.Endpoint.Binding).ReaderQuotas.MaxStringContentLength = Int32.MaxValue; 
     ((NetTcpBinding)cf.Endpoint.Binding).ReliableSession.Enabled = false; 
     ((NetTcpBinding)cf.Endpoint.Binding).ReliableSession.InactivityTimeout = new TimeSpan(0, 10, 0); ; 
     ((NetTcpBinding)cf.Endpoint.Binding).ReliableSession.Ordered = true; 
     foreach (OperationDescription op in cf.Endpoint.Contract.Operations) 
     { 
      DataContractSerializerOperationBehavior dataContractBehavior = 
      op.Behaviors[typeof(DataContractSerializerOperationBehavior)] 
      as DataContractSerializerOperationBehavior; 
      if (dataContractBehavior != null) 
      { 
       dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue; 
      } 

     } 
     Globs.catClient = cf.CreateChannel(new EndpointAddress("net.tcp://localhost:8732/WCFSrvLib")); 
     if (Globs.catClient == null) 
      throw new Exception("Unable to initialize server"); 
     try 
     { 
      Globs.CatData = new List<CATData>(Globs.catClient.getData(out err, Globs.connsrv)); 
      Globs.HandleError(err); 
      UpdateProgressBar(); 
     } 
     catch (Exception e) 
     { 
      if (!NotifyError("Data", e.Message)) 
       return false; 
     } 

有一对夫妇的是内部功能,所以不在这里定义,但他们不是问题的关键。 请注意,在尝试查找此问题的解决方案时,已经放置了channelfactory中的所有设置。

如果您需要更详细或代码,只是要求提前:)

感谢, Morenz。

回答

0

我解决了! 每次都会发生这种情况......我把脑袋砸了几个小时,然后我决定在某个地方寻求帮助,然后......在一段时间后,我追究这个问题。

在这种情况下,我忘记了WCF服务中的App.config(我只在WCF库中做过它...我做了一些测试,检查是否可以在没有app.config的情况下运行系统,并且我忘记了读取到服务器服务项目)。

感谢您的关注 Morenz