在C#中增加WCF Web服务的超时
我目前有一个在服务器上调用Web服务进行搜索的应用程序.我们可以预期会返回大量数据,所以搜索花费的时间超过一分钟是常规的.
我们收到如下大量搜索的以下错误消息:
这是我们已经在StackOverflow上发布的多个问题中提出的问题,不幸的是没有可用的解决方案帮助我解决了这个问题,甚至可以配置超时窗口. 我们都改变了客户端的app.config,增加了所有超时(CloseTimeout,OpenTimeout,ReceiveTimeout和SendTimeout)以及服务器上的服务的所有web.config值(closeTimeout,openTimeout和SendTimeout). 这些更改都没有任何影响,我仍然收到分钟超时.任何想法,为什么改变这些价值观会没有影响? 在下面的例子中,我们放下了时间让我们不必在测试期间等待整整一个小时. Web.config文件: <configuration> <system.web> <compilation targetFramework="4.0" /> </system.web> <system.diagnostics> <trace autoflush="true" /> <sources> <source name="System.Net"> <listeners> <add name="TraceFile" /> </listeners> </source> <source name="System.Net.Sockets"> <listeners> <add name="TraceFile" /> </listeners> </source> </sources> <sharedListeners> <add name="TraceFile" type="System.Diagnostics.TextWriterTraceListener" initializeData="trace.log" /> </sharedListeners> <switches> <add name="System.Net" value="Verbose" /> <add name="System.Net.Sockets" value="Verbose" /> </switches> </system.diagnostics> <system.serviceModel> <diagnostics> <messageLogging logMalformedMessages="false" logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="false" /> </diagnostics> <services> <service behaviorConfiguration="SearchIndexServiceBehavior" name="SearchIndex.Service"> <endpoint address="" binding="basicHttpBinding" contract="ISearchIndexServices" /> <host> <timeouts closeTimeout="00:00:10" /> </host> </service> </services> <bindings> <basicHttpBinding> <binding closeTimeout="00:00:10" openTimeout="00:00:15" sendTimeout="00:00:20" receiveTimeout="00:00:25" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> </binding> </basicHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="SearchIndexServiceBehavior"> <serviceMetadata httpGetEnabled="false" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> <system.transactions> <defaultSettings timeout="00:05:00" /> </system.transactions> </configuration> 的app.config <configuration> <configSections> </configSections> <startup> </startup> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_ISearchIndexServices" closeTimeout="00:00:10" openTimeout="00:00:15" receiveTimeout="00:10:00" sendTimeout="00:00:20" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="5242880" maxBufferPoolSize="524288" maxReceivedMessageSize="5242880" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <readerQuotas maxDepth="32" maxStringContentLength="5242880"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://MyServer/SearchIndexService/SearchIndexServices.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISearchIndexServices" contract="WFC.ISearchIndexServices" name="BasicHttpBinding_ISearchIndexServices" /> </client> </system.serviceModel> </configuration> 解决方法
我认为你可能会碰到客户端请求通道的OperationTimeout,由于某些原因,通过标准配置属性不容易调整.
在调用长时间运行的操作之前,请尝试在客户端代码中: ((IContextChannel)clientProxy.InnerChannel).OperationTimeout = new TimeSpan(0,30,0); // For 30 minute timeout - adjust as necessary 其中clientProxy是服务引用生成的Client类的实例(它来自ClientBase< ISearchIndexService>). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- Ruby File IO Hang
- c – 为什么SIMD乘法不比非SIMD乘法更快?
- 飞镖忍者 quick-cocos2d-x3.2
- 正则表达式报错 PatternSyntaxException Unclosed group ne
- PostgreSQL数据库 OLTP高并发请求性能优化
- iphone – 改变uialertview大小的问题
- ios – Xcode 5 SpriteKit粒子发射器没有出现在编辑器中
- c# – 使用datareader读取数百万个数据时,如何避免数据库连
- c# – 初始化属性的良好做法?
- ios – 在tabViewController setSelectedIndex之后,旋转不为