我有一个使用 tcp 绑定的服务,该服务允许客户端与数据库交互。我使用 EF 和自我跟踪实体。
我想做的一件事是将文件存储在数据库中,为了不使线路过载,我有两个表及其对应的实体。一个表 Documents 包含文档信息(类型、大小...等),另一个表 Files 存储二进制信息,即文件。
好吧,在本地,当我在同一台计算机上运行客户端和服务时,我可以存储我想要的文件。我尝试使用 6MB 的文件。但是如果我在同一局域网的其他计算机上运行客户端,那么我会遇到很多问题。
例如,如果我尝试存储一个 50kB 的小文件,我没有问题,但如果我尝试存储 6MB 的文件,那么我会得到不同的错误。
例如,如果我在客户端配置一个低超时,例如 1 分钟,我会收到错误:
System.TimeoutException:发送到 net.tcp://192.168.1.5:7997/CMMSHost 的此请求操作未在配置的超时 (00:01:00) 内收到回复。
如果我将客户端配置为超时 10 分钟,则会收到以下错误:
服务器没有提供有意义的回复
该服务托管在 wpf 应用程序中,并且在将文档添加到数据库中的服务的 Begin 方法中,我发送带有日志的文本以了解是否收到呼叫。当我收到一些错误时,没有收到呼叫,所以我认为问题可能是自我跟踪实体由于某种原因没有到达服务。
我的服务的 app.config 如下:
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="tcpBinding"
name="NetTcpBindingEndpoint"
contract="GTS.CMMS.Service.IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint contract="IMetadataExchange" binding="mexTcpBinding" address="net.tcp://localhost:5000/mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="behaviorConfig">
<!--
<serviceMetadata httpGetEnabled="true" />-->
<!--Necesario para poder enviar excepciones desde el servicio al cliente.-->
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="100" />
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="tcpBinding" maxBufferSize="67108864"
maxReceivedMessageSize="67108864" maxBufferPoolSize="67108864"
transferMode="Buffered" closeTimeout="00:00:10"
openTimeout="00:00:10" receiveTimeout="00:20:00"
sendTimeout="00:01:00" maxConnections="100">
<security mode="None"/>
<readerQuotas maxArrayLength="67108864" maxBytesPerRead="67108864" maxStringContentLength="67108864"/>
<reliableSession enabled="true" inactivityTimeout="00:20:00" />
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
客户端配置是:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:20:00"
enabled="true" />
<security mode="None">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://192.168.1.5:7997/CMMSHost" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService" contract="IService"
name="NetTcpBinding_IService" />
</client>
</system.serviceModel>
</configuration>
我使用大的 readquotes,试图丢弃问题是文件的大小,但问题仍然存在。
谢谢。