我在本地使用WCF服务来计算一些信息,这是C#,并返回数据。
我返回的数据是一个浮动列表List<List< float>>
的列表,其中共有4个浮点数。每个浮动列表包含400个项目,每个集合中有180个这样的列表。那么List<List<float>>
的4个
我最初没有足够的空间错误,然后将大小更新为最大2,000,000字节。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IExternalBallistics" closeTimeout="01:10:00"
openTimeout="01:10:00" receiveTimeout="01:10:00" sendTimeout="01:10:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="2000000" maxBufferSize="2000000" maxConnections="10"
maxReceivedMessageSize="2000000">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:6100/ExternalBallistics"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IExternalBallistics"
contract="IExternalBallistics" name="NetTcpBinding_IExternalBallistics" />
</client>
</system.serviceModel>
</configuration>
我也在我的主机中手动设置了这些值。
private void InitializeServiceHost()
{
if (_serviceHost != null)
{
_serviceHost.Close();
}
Uri address = new Uri("net.tcp://localhost:6100/ExternalBallistics");
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
binding.MaxReceivedMessageSize = 2000000;
binding.MaxBufferSize = 2000000;
binding.MaxBufferPoolSize = 2000000;
binding.CloseTimeout = new TimeSpan(1, 10, 0);
binding.OpenTimeout = new TimeSpan(1, 10, 0);
binding.ReceiveTimeout = new TimeSpan(1, 10, 0);
binding.SendTimeout = new TimeSpan(1, 10, 0);
_serviceHost = new ServiceHost(typeof(ExternalBallisticsImpl), address);
_serviceHost.Description.Behaviors.Add(GetMetadataBehavior());
_serviceHost.CloseTimeout = new TimeSpan(1, 10, 0);
_serviceHost.OpenTimeout = new TimeSpan(1, 10, 0);
_serviceHost.AddServiceEndpoint(typeof(IExternalBallistics), binding, address);
_serviceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
_serviceHost.Open();
}
我还将超时设置为1小时10分钟。
我得到的错误是
The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '01:09:59.9770000'.
现在超时发生在30秒内。我有一个单元测试我正在运行,服务正确地执行所有操作,并且回复包含有效数据,但是当它返回此回复时,我总是会收到此错误。
我一直在搜索,我无法得到任何解决方案,因为我看到的只是通知我增加缓冲区/超时时间。
答案 0 :(得分:1)
虽然它被报告为超时例外,但可能是另一个问题。
您是否尝试Set set maxItemsInObjectGraph以确保您可以发送大对象图。
<serviceBehaviors>
<behavior name="MyBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
只需按照以下链接,希望有所帮助:
http://davybrion.com/blog/2008/09/wcf-and-large-amounts-of-data/
答案 1 :(得分:1)
正如@Tim在他的评论中所建议的那样,这可能是服务器在约30秒后无法与客户端通信的问题。客户可能已经关闭了它的连接。
确保客户端上的绑定设置与服务器的绑定设置相匹配。特别是,请确保客户端的receiveTimeout
值类似于服务器的sendTimeout
。