WCF超时
参照网上的例子做的个异步上传,上传单个300M文件没问题,开了4个一起上传就报错了,但是上传几M那种4个一起开就不出错,不知道为什么,感觉同时传多个一到某个时间(2分钟左右)就报错,小文件是时间短没报出来,4个一起上传的时候,调
试页面会出个错误(服务器连接超时),但是不停止调试这些文件都能完整上传,只是页面早就报错了,也就是说页面报错没
影响到上传。到底是配置问题还是上传代码的问题,高手指点下,小弟新手,在线等,配置文件如下:
服务端:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime maxRequestLength="2097151" />
</system.web>
<appSettings>
<add key="filePath" value="E:\Download" />
</appSettings>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.; Initial Catalog=TestDB; User ID=sa; Password=123" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="StreamedHTTP" maxReceivedMessageSize="9223372036854775807" messageEncoding="Mtom" transferMode="Streamed" sendTimeout="00:30:00" >
<readerQuotas maxArrayLength="20000000"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="DefaultBehavior" name="ZXWCFService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="StreamedHTTP"
contract="IZXWCFService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/ZXWeb/ZXWCFService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
客户端:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime maxRequestLength="2097151" />
</system.web>
<appSettings>
<add key="filePath" value="E:\Upload3" />
</appSettings>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.; Initial Catalog=TestDB1; User ID=sa; Password=123" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IZXWCFService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/ZXWeb/ZXWCFService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IZXWCFService" contract="ZXWCFService.IZXWCFService"
name="BasicHttpBinding_IZXWCFService" />
</client>
</system.serviceModel>
</configuration>
--------------------编程问答-------------------- 来人解决下吧 --------------------编程问答-------------------- <system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IZXWCFService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
这里面的前面是max的数据后面都加几个0试试。 --------------------编程问答-------------------- 原来觉得是你客户端没有及时关闭导致的。
但看你配置:
<serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>
都是100厄。。。按楼上的方法改改看把。
btw: 开了4个一起上传就报错了,但是上传几M那种4个一起开就不出错 什么意思?
4个一起上传和4个一个开什么区别? --------------------编程问答-------------------- 属于并发吗? --------------------编程问答-------------------- 改了,没用,继续测了是上传到385M出的问题,我意思是我上传几M那种,开了4个客户端一起上传就没事,如果是1 200M的就出错了 --------------------编程问答-------------------- 我想做并发,但是参考的这个例子也没觉得哪里体现了并发,我开几个客户端同时上传,服务器都开始接收,这样算实现并发不? --------------------编程问答-------------------- 现在发现不管是并发还是单个传,只要这次上传量达到385M就出错,但是我客户端和服务端的配置文件把里面的值都改最大了,还是出错
服务端:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="StreamedHTTP" maxReceivedMessageSize="9223372036854775807" messageEncoding="Mtom" transferMode="Streamed" sendTimeout="00:30:00" >
<readerQuotas maxArrayLength="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="DefaultBehavior" name="ZXWCFService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="StreamedHTTP"
contract="IZXWCFService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/ZXWeb/ZXWCFService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="1000"/>
</behavior>
</serviceBehaviors>
客户端:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IZXWCFService" closeTimeout="00:05:00"
openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="9223372036854775807"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/ZXWeb/ZXWCFService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IZXWCFService" contract="ZXWCFService.IZXWCFService"
name="BasicHttpBinding_IZXWCFService" />
</client>
</system.serviceModel> --------------------编程问答-------------------- 我自己测试了下。上传个2G的东东没有问题。不过我是用WinformHost的。不知道是不是IIS Host的问题?
<system.web>配置节下的<httpRuntime maxRequestLength="2097151" /> 有设置吗? --------------------编程问答-------------------- --------------------编程问答--------------------
--------------------编程问答-------------------- 如果WCF以IIS作为宿主,WCF传输数据量的能力受HttpRunttime MaxRequestLength属性的制约,HttpRunttime MaxRequestLength 设置请求的最大大小(以千字节为单位)。默认大小为 4096 KB (4 MB),允许的最大值是2097151。 --------------------编程问答-------------------- remark,明天试一下
<endpoint address="" binding="wsHttpBinding" contract="" />
设置下最大上传大小
补充:.NET技术 , .NET Framework