resttemplate默认超时时间_使用微软数据通信框架WCF:客户端调用服务超时分析

首先给出对调用超时的分析和解决办法,然后在给出完整和应用代码。

1 客户端调用超时

运行客户端,执行调用

ServiceProxy proxy = new ServiceProxy();string s = proxy.GetData(1);

通过配置sendTimeout参数设定超时时间,超时时间默认为1分钟,上述配置中采用了默认超时时间。

InnerException

resttemplate默认超时时间_使用微软数据通信框架WCF:客户端调用服务超时分析_第1张图片

Message

请求通道在等待 00:00:59.9469970 以后答复时超时。增加传递给请求调用的超时值,或者增加绑定上的 SendTimeout 值。分配给此操作的时间可能已经是更长超时的一部分。

Stacktrace:

Server stack trace:

在 System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)

在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)

在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:

在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

在 Client.IService.GetData(Int32 value)

在 Client.ServiceClient.GetData(Int32 value) 位置 e:projgxz_myselfWCF_Find_ErrorClientServiceProxy.cs:行号 52

在 Client.ServiceProxy.GetData(Int32 value) 位置 e:projgxz_myselfWCF_Find_ErrorClientServiceProxy.cs:行号 19

在 Client.Program.Main(String[] args) 位置 e:projgxz_myselfWCF_Find_ErrorClientProgram.cs:行号 17

增大客户端调用超时时间,可解决超时问题

例如,超时时间设置为10分钟,满足此次调用需求。

2 非活动状态的最大时间间隔

通过配置receiveTimeout设定时间间隔,默认值为 10 分钟。

服务实例化模式改为为会话模式:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Reentrant)]

服务端配置

客户端配置

客户端调用

using (ServiceClient client = new ServiceClient()) { StreamReader sr = new StreamReader("D:CSBMTEMP.txt

你可能感兴趣的:(服务端设置超时时间)