WCF Web服务 - 增加超时

Rya*_*yan 0 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>
Run Code Online (Sandbox Code Playgroud)

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

mar*_*c_s 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>
Run Code Online (Sandbox Code Playgroud)

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

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

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

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