WCF Web服务 - 增加超时

时间:2011-02-22 21:26:26

标签: c# wcf

我明白了:

  

接收到http://localhost:8732/Design_Time_Addresses/PersistencyService/Service1/的HTTP响应时发生错误。这可能是由于服务端点绑定不使用HTTP协议。这也可能是由于服务器中止HTTP请求上下文(可能是由于服务关闭)。有关详细信息,请参阅服务器日志。

为什么我会这样?我认为这是因为该方法需要大约1分钟才能完成。如何禁用任何时间限制?

我在VS中运行一个在同一解决方案中使用WCF服务的Windows表单项目时得到了这个

我的WCF配置: 修改

<system.serviceModel>
   <bindings>
      <wsHttpBinding>
        <binding name="LongRunning" sendTimeout="00:10:00" />
      </wsHttpBinding>
   </bindings>
   <client>
      <endpoint name="Default"          
                address="http://localhost:8732/Design_Time_Addresses/PersistencyService/Service1/"         
                binding="wsHttpBinding"                    
                bindingConfiguration="LongRunning"
                contract="PersistencyService.IService1" />
   </client>
   <services>
      <service name="PersistencyService.Service1">
         <endpoint 
             address="" 
             binding="wsHttpBinding"  bindingConfiguration=""
             contract="PersistencyService.IService1" >
             <identity>
                <dns value="localhost" />
             </identity>
         </endpoint>
         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
         <host>
            <baseAddresses>
               <add baseAddress="http://localhost:8732/Design_Time_Addresses/PersistencyService/Service1/" />
            </baseAddresses>
         </host>
      </service>
   </services>
   <behaviors>
      <serviceBehaviors>
         <behavior>
            <serviceMetadata httpGetEnabled="True"/>
            <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
   </behaviors>
</system.serviceModel>

异常消息是远程主机强制关闭现有连接。 我还必须补充一点,我从服务中获得了大约70MB的数据

1 个答案:

答案 0 :(得分:6)

在客户端,您需要为app.config添加一些设置:

<system.serviceModel>
   <bindings>
      <wsHttpBinding>
         <binding name="LongRunning" sendTimeout="00:10:00" />
      </wsHttpBinding>
   </bindings>
   <client>
       <endpoint name="Default"
           address="....."
           binding="wsHttpBinding"
           bindingConfiguration="LongRunning"
           contract="IYourServiceContract" />
   </client>
</system.serviceModel>

你没有给我们太多的东西 - 没有配置,没有......所以我只是猜测你可能有什么设置。

基本上,您需要为您正在使用的绑定类型定义绑定配置,并且需要增加该绑定配置的sendTimeout属性(在我的示例中) : 10分钟)。你不能完全关闭超时 - 你可以增加它,但不能关闭它。

然后,您的客户端配置必须通过在bindingConfiguration="...."配置上指定<endpoint>属性并使用与绑定配置相同的名称来引用您已定义的绑定配置。当你定义它时。

也许这已经足够了 - 但也许,您还需要增加服务器方面的部分超时时间。首先尝试这个 - 如果它不起作用,请再次询问 - 并,下次:向我们提供一些更有用的信息,例如您的代码和配置!

相关问题