简体   繁体   English

WCF Web服务-增加超时

[英]WCF web service - increase timeout

I get this: 我得到这个:

An error occurred while receiving the HTTP response to http://localhost:8732/Design_Time_Addresses/PersistencyService/Service1/ . 收到对http:// localhost:8732 / Design_Time_Addresses / PersistencyService / Service1 /的HTTP响应时发生错误。 This could be due to the service endpoint binding not using the HTTP protocol. 这可能是由于服务端点绑定未使用HTTP协议。 This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). 这也可能是由于服务器终止了HTTP请求上下文(可能是由于服务关闭了)。 See server logs for more details. 有关更多详细信息,请参见服务器日志。

Why do I get this? 为什么我得到这个? I assume it is because the method takes about 1 min to complete. 我认为这是因为该方法大约需要1分钟才能完成。 How can disable any time limit? 如何禁用任何时间限制?

I get this when running in VS a Windows form project that uses a WCF service in the same solution 我在以相同解决方案使用WCF服务的Windows窗体项目VS中运行时得到此消息

My WCF configuration: edit: 我的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>

The exception message is An existing connection was forcibly closed by the remote host. 异常消息是:远程主机强行关闭了现有连接。 I must also add that I get about 70MB of data from the service 我还必须补充一点,我从该服务中获得了大约70MB的数据

On the client side, you need to add some settings to your app.config : 在客户端,您需要向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>

You didn't give us much to go on - no config, nothing.... so I'm left just guessing what settings you might have. 您没有给我们太多的工作-没有配置,什么都没有...。所以我只是猜测您可能有什么设置。

Basically, you need to define a binding configuration for the type of binding you're using, and you need to increase the sendTimeout attribute on that binding configuration (here in my sample: 10 minutes). 基本上,您需要为正在使用的绑定类型定义绑定配置 ,并且需要在该绑定配置上增加sendTimeout属性(在我的示例中为10分钟)。 You cannot completely turn off the timeout - you can increase it, but not turn it off. 您无法完全关闭超时-您可以增加超时,但不能将其关闭。

Then, your client side config must make a reference to that binding configuration you've defined, by specifying a bindingConfiguration="...." attribute on the <endpoint> configuration, and using the same name for the binding configuration as when you defined it. 然后,您的客户端配置必须引用您已定义的绑定配置,方法是在<endpoint>配置上指定bindingConfiguration="...."属性,并为绑定配置使用与您使用时相同的名称定义它。

Maybe this is enough - but maybe, you'll also need to increase some of the timeouts on the server side. 也许这足够了,但是也许,您还需要增加服务器端的某些超时时间。 Try this first - if it doesn't work, come back and ask again - and please , next time: provide us with some more useful info, like your code and config! 请先尝试一下-如果不起作用,请再次询问-下一次, :为我们提供一些更有用的信息,例如您的代码和配置!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM