zoukankan      html  css  js  c++  java
  • wcf 中客户端调用之死 感悟 wcf与原来的webservice2.0 的客户端调用区别(wcf调用完不关闭的话那就把web服务搞死了)

    说到wcf,本人也是刚刚使用所以不是很熟悉

    在做项目的时候采用webservice+客户端程序架构

    写了一个wcf中的webservice之后,又写了很多的客户端exe程序,有的是轮询调用这个webservice方法,有的是仅仅调用一次webservice方法的exe程序,

    在单元测试的时候都是没有遇到问题,结果却在做整合测试的时候发现发现了如下的错误,倒是所有程序都不能正常运行:

    System.TimeoutException: The request channel timed out while waiting for a reply after 00:01:00. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout. ---> System.TimeoutException: The HTTP request to 'http://192.168.3.112:8080/Service.svc' has exceeded the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout. ---> System.Net.WebException: The operation has timed out
       at System.Net.HttpWebRequest.GetResponse()
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       --- End of inner exception stack trace ---
       at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       --- End of inner exception stack trace ---

    Server stack trace: 
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at PortalClient.SvcRef.IService.GetExcelToTxt()
       at PortalClient.SvcRef.ServiceClient.GetExcelToTxt() in D:MAXNET_PROJECT3_SourceCodeMAXNET5_MaximOOSMaximOOSMaxim.PortalClientService ReferencesSvcRefReference.cs:line 2653
       at Maxim.PortalClient.SrvBox.btnTestWriteTxt_Click(Object sender, EventArgs e) in D:MAXNET_PROJECT3_SourceCodeMAXNET5_MaximOOSMaximOOSMaxim.PortalClientSrvBox.cs:line 26

    看了上面的错误,估计大家都应该知道是什么错误了吧,对,是调用超时。

    当时看到这个错误,我的第一反应就是可能传输的问题,但是代码没有问题,因此我就修改了客户端调用webservice的响应时间改成5分钟,结果令人不满意,还是不行

    后来我就试了一下重启iis结果,我发现在第一次调用webservice的时候成功了,但是在随后的调用中又出现了上面的错误,但是真的差点崩溃了,

    一直到加班结束,我在回家的路上突然想到了我以前遇到超时的问题是数据库连接超时,是因为连接打开然后没有关闭,导致数据打开的连接数超过上限以致超时的,

    回到家后我立即采用简单的测试,终于发现了在wcf中的webservice也是要关闭的(其实在示例代码中有说要close()的,可是我没注意),如果不关闭的话,我测试了一下,档调用webservice超过10次的时候,webservcie就死掉了,以致以后再调都不可以了(这个会不会是微软的bug呀,因为如果这种问题出现的话,要想让webservice死掉的话,我只有调用webservice然后不做关闭处理就可以实现了),这个和以前的webservice(asmx)方案是完全不一样的,webservice(asmx)不需要关闭

    还有我发现调用wcf写的服务没有调用webservice(asmx)的速度开,性能可能wcf没有webservice(asmx)好,但是可靠性应该还可以的

    这个是小弟的第一篇blog,谢谢支持!

  • 相关阅读:
    37.leetcode11_container_with_most_water
    36.leetcode8_string_to_integer
    34.leetcode15&5_time_limit_exceeded
    35.leetcode15_3Sum
    33.leetcode6_zigzag_conversion
    32.leetcode3_longest_substring_without_repeating_characters
    31.leetcode2_add_two_numbers
    29.leetcode172_factorial_trailing_zeroes
    30.leetcode171_excel_sheet_column_number
    [LeetCode] 43.Multiply Strings 字符串相乘
  • 原文地址:https://www.cnblogs.com/Alex80/p/8870391.html
Copyright © 2011-2022 走看看