【问题标题】:WCF web service - increase timeoutWCF Web 服务 - 增加超时
【发布时间】:2011-02-22 21:26:25
【问题描述】:

我明白了:

接收到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 的数据

【问题讨论】:

  • 嗨,Ryan,只要你调用“超时”时间限制,你在谷歌上搜索这个就不会有太多运气了 ;-) :D

标签: c# wcf


【解决方案1】:

在客户端,您需要将一些设置添加到您的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分钟)。您不能完全关闭超时 - 您可以增加它,但不能关闭它。

然后,您的客户端配置必须引用您已定义的绑定配置,方法是在 &lt;endpoint&gt; 配置上指定 bindingConfiguration="...." 属性,并为绑定配置使用与您定义时相同的名称.

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

【讨论】:

  • 我已经添加了配置文件。我仍然收到此错误,我不知道为什么
  • @Ryan:好的,您正在使用 basicHttpBinding - 您是否相应地调整了我的配置??
  • 我已经编辑了新的配置。我试图匹配你的代码。如果有什么不一样的请告诉我!我仍然有同样的问题。我使用发现按钮在同一解决方案中添加对服务的引用。到目前为止,谢谢或您的帮助,希望您能帮助我!
  • @Ryan:您能否向我们展示您与该服务的服务合同,以及您如何从您的客户端代码调用该服务?配置对我来说似乎很好......
  • 我认为这是因为我需要通过该服务获取大量数据。我可以以某种方式增加它吗?
猜你喜欢
  • 2010-12-03
  • 2012-03-12
  • 1970-01-01
  • 2014-03-31
  • 1970-01-01
  • 2018-04-06
  • 2013-12-02
  • 2011-11-08
  • 2012-11-24
相关资源
最近更新 更多