ReceiveTimeout的作用是什么 [英] What is the effect of ReceiveTimeout

查看:317
本文介绍了ReceiveTimeout的作用是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解ReceiveTimeout和InactiveTimeout的含义和作用.

I want to understanding the meaning and effect of ReceiveTimeout and InactiveTimeout.

这是我的实验:

(a)测试服务和服务合同:

(a) testing service and service contract:

   {
       静态DateTime ClassTime = DateTime.Now ;
         DateTime InstanceTime;
      公共Service1()
       {
           InstanceTime = DateTime.Now ;
       }
      公共字符串GetData(字符串值)
       {
          返回 string.Format("ClassTime是{0},您输入的是:{1},InstanceTime是{2}",ClassTime,值,InstanceTime);
       }
    }
    [ServiceContract]
   公共接口IService1
    {
       [OperationContract]
      字符串GetData(字符串值);
    }
(b)Web.config(注意ReceiveTimeout和InactivityTimeout均为1分钟)

    {
        static DateTime ClassTime=DateTime.Now;
        DateTime InstanceTime;
        public Service1()
        {
            InstanceTime = DateTime.Now;
        }
        public string GetData(string value)
        {
            return string.Format("ClassTime is {0}, You entered: {1}, InstanceTime is {2}", ClassTime, value, InstanceTime);
        }
    }
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(string value);
    }
(b) Web.config(Note ReceiveTimeout and InactivityTimeout are both 1 minute)

<?xml version ="1.0" encoding ="utf-8"?>
< configuration>

  < system.web>
    < compilation debug ="true"; targetFramework ="4.0" />
  </system.web>
  < system.serviceModel>
    < protocolMapping>
     <删除方案="http"; />
     < add scheme ="http" binding ="wsHttpBinding" />
    </protocolMapping>
    < bindings>
     < wsHttpBinding>
       < binding name ="NewBinding0&"; receiveTimeout ="00:01:00" >
         < reliableSession inactivityTimeout =" 00:01:00" />
       </binding>
     </wsHttpBinding>
    </bindings>
    <行为>
     < serviceBehaviors>
       <行为>
         < serviceMetadata httpGetEnabled ="true"/>
         < serviceDebug includeExceptionDetailInFaults ="false"/>
       </行为>
     </serviceBehaviors>
    </行为>
    < serviceHostingEnvironment multipleSiteBindingsEnabled ="true"; />
  </system.serviceModel>
 < system.webServer>
    < modules runAllManagedModulesForAllRequests ="true"/>
  </system.webServer>
 
</configuration>

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <protocolMapping>
      <remove scheme="http" />
      <add scheme="http" binding="wsHttpBinding" />
    </protocolMapping>
    <bindings>
      <wsHttpBinding>
        <binding name="NewBinding0" receiveTimeout="00:01:00">
          <reliableSession inactivityTimeout="00:01:00" />
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
 
</configuration>

(c)客户端配置

<?xml version ="1.0" encoding ="utf-8" ?>
< configuration>
    < system.serviceModel>
       < bindings>
           < wsHttpBinding>
                             < binding name =" WSHttpBinding_IService1" closeTimeout ="00:01:00"
                    openTimeout ="00:01:00" receiveTimeout ="00:10:00" sendTimeout ="00:01:00"
                    BypassProxyOnLocal ="false"; transactionFlow =假". hostNameComparisonMode =" StrongWildcard"
                    maxBufferPoolSize ="524288" maxReceivedMessageSize ="65536"
                    messageEncoding =文本" textEncoding ="utf-8"; useDefaultWebProxy ='"true"
                    allowCookies ="false">
                    < readerQuotas maxDepth ="32" maxStringContentLength ="8192" maxArrayLength ="16384"
               b maxBytesPerRead ="4096". maxNameTableCharCount ="16384"; />
                    < reliableSessionordered ="true"; inactivityTimeout ="00:10:00"
               b enabled ="false" />
                    <安全模式=消息">
               b < transport clientCredentialType ="Windows"; proxyCredentialType =无"
              nbsp; bsp    realm =" />
               b < message clientCredentialType ="Windows" negotiationServiceCredential ="true"
              nbsp; bsp    algorithmSuite =默认" />
                    </security>
                             </binding>
           </wsHttpBinding>
       </bindings>
       < client>
           <端点地址="http://localhost/WcfTimeoutTest/Service1.svc"
                             binding ="wsHttpBinding" bindingConfiguration ="WSHttpBinding_IService1"
                             contract ="ServiceReference1.IService1" name =" WSHttpBinding_IService1">
                             < identity>
                    < servicePrincipalName value =主机/std-win7-64-PC"; />
                             </identity>
           </endpoint>
       </client>
    </system.serviceModel>
</configuration>

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost/WcfTimeoutTest/Service1.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
                contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">
                <identity>
                    <servicePrincipalName value="host/std-win7-64-PC" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

我期望的是:

客户端第一次致电GetData("ABC"),ClassTime.并且响应消息中的InstanceTime相等.

First time the client call  GetData("ABC"), ClassTime  and InstanceTime is equal in the response message.

第二时间(第一时间之后的时间间隔小于1分钟),客户端调用GetData("ABC"),响应消息中的ClassTime为与第一次相同,响应消息中的InstanceTime不是和第一次一样.

Second time(the time lag after First time is less than 1 minute) the client call GetData("ABC"),ClassTime in response message is  same as first time, InstanceTime in response message is not  same as first time.

第三次(比第二次晚 2分钟)客户端调用GetData("ABC"),响应消息中的ClassTime不是与第一次相同(由于辍学).

Third time( 2 minutes later than the second time) the client call GetData("ABC"), ClassTime in response message is not  same as in first time(due to dropout).

但是我得到了所有三个时间的 one ClassTime和三个不同的InstanceTime.

But I got one ClassTime for all three times and three different InstanceTime.

有人可以帮我解释一下吗?

Can some one explain this for me ?

HJY ---随时尝试快乐---

HJY ---try to be happy in any time---

推荐答案

hjyanghj,

Hi hjyanghj,

您可以降低测试的 inactivityTimout 值.

据我了解,ReceiveTimeout是空闲超时 可以保持在该时段内的值,在此期间不接收任何应用程序消息,并且此时间段 大于设置的值 ,然后服务器 将主动断开与 客户端的连接 .

According to my understanding, ReceiveTimeout is the idle timeout value during the period connection can remain, during which no application messages are received and this time period is bigger than the set value, then the server will drop the connection with the client actively.

InactivityTimeout指示空闲超时值 in case of the 在非活动时间段内,如果时间是客户端和 服务器端 已断开连接 大于设置的值 ,然后触发事件.

InactivityTimeout indicates the idle timeout value that in the case of the client and the server side has been disconnected, during inactive periods, if the time is bigger than the set value, then trigger an event.

InactivityTimeout是否大于ReceiveTimeout,这没有任何意义.

It make no sense if the InactivityTimeout is bigger than ReceiveTimeout.

如果您希望在客户端断开连接异常断开连接,因此设置 inactivityTimout 尽可能短,例如5秒.如果 想要制作 客户端和服务器 保持长时间连接 ,然后设置 receiveTimeout 尽可能大 示例 1小时.

If you want the event be triggered immediately when clients disconnect or abnormal disconnection, so set inactivityTimout as small as possible, for example, 5 seconds. If you want to make the client and server keep connection for a long period, then set receiveTimeout as large as possible, for example, 1 hour.

最好的问候.


这篇关于ReceiveTimeout的作用是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆