WCF 不活动超时

Nul*_*nce 4 .net c# wcf app-config

我创建了一个非常简单的 WCF 服务,托管在 Windows 服务上,严格遵循 MSDN 上的示例:http ://msdn.microsoft.com/en-us/library/ff649818.aspx

如果我在第一次调用后 10 分钟内第二次调用我的服务,我将收到不活动超时错误。据我所知,这是WCF客户端的默认设置。

但是,当我更改我的 app.config 时

 <reliableSession ordered="true" inactivityTimeout="00:10:00"
                   enabled="false" />
Run Code Online (Sandbox Code Playgroud)

 <reliableSession ordered="true" inactivityTimeout="infinite"
                    enabled="true" />
Run Code Online (Sandbox Code Playgroud)

当我尝试拨打电话时出现此错误:

由于 EndpointDispatcher 上的 ContractFilter 不匹配,无法在接收方处处理操作为“http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence”的消息。这可能是因为合同不匹配(发送者和接收者之间的操作不匹配)或发送者和接收者之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。

这就是我的 WCF 配置文件在 Windows 服务上的样子。

  <system.serviceModel>
<services>
  <service name="Asis.IBSS.Milestone.WCFService.ServiceImplementation.VideoService">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract="Asis.IBSS.Milestone.WCFService.ServiceContract.IVideoService">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange"/>
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8555/MilestoneService"/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="false"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)

我的问题是,如何将 inactivityTimeout 设置为 inifinte,并避免出现错误?

lex*_*x87 5

我认为您还需要将绑定上的 receiveTimeout 设置为无限。receiveTimeout 和 inactivityTimeout 这两个属性彼此有一些依赖关系,如果将 inactivityTimeout 设置为高于 receiveTimeout 的值,则可能会出现一些错误。

例如:

        <bindings>
        <wsFederationHttpBinding>
    <binding name="someServiceFederatedBinding" maxReceivedMessageSize="2147483647" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="01:00:00">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    </binding>
        </wsFederationHttpBinding>
    </bindings>
Run Code Online (Sandbox Code Playgroud)

并将绑定配置 =“someServiceFederatedBinding”放入您的服务中。