增加调用wcf服务的C#类库(DLL)超时

时间:2017-10-25 06:30:56

标签: c# winforms wcf timeout class-library

我有一个类库,我在其上调用WCF服务。此服务大约需要3分钟才能完成。我正在使用Windows Forms,我将executionTimeout添加到httpRuntime元素中的App.Config。不过,它不会等到它完成交易。如何为通话留出更长的等待时间?

我在Windows窗体应用程序的App.Config中添加了以下代码

Select t1.*, t2.tid is not null as ex 
from table1 t1
left join table2 t2 on t1.tid = t2.tid and t2.sid = <some_value>

我点击按钮点击我的服务。

    <system.web>
   <compilation debug="false"/>
    <httpRuntime executionTimeout="360" />  
  </system.web>

但是上面调用TimesOut时请求需要一点时间才能响应。

1 个答案:

答案 0 :(得分:0)

您需要在WCF应用程序以及Windows窗体应用程序

上设置超时

1)WCF应用程序:请在web.config中添加以下更改

=&GT;第一次改变

<bindings>
   <basicHttpBinding>
        <binding name="BasicHttpsBindingConfig" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
         receiveTimeout="00:10:00" sendTimeout="00:10:00">
    <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647"/>
        </binding>
   </basicHttpBinding>
</bindings>

=&GT;第二次更改:在web.config中增加超时

<configuration>
  <system.web>
  <httpRuntime executionTimeout="600"/>
  </system.web>
</configuration>

2)Windows窗体应用示例:

public static void Main()  
        {  
            Uri baseAddress = new Uri("http://localhost/MyServer/MyService");  

            try  
            {  
                ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService));  

                WSHttpBinding binding = new WSHttpBinding();  
                binding.OpenTimeout = new TimeSpan(0, 10, 0);  
                binding.CloseTimeout = new TimeSpan(0, 10, 0);  
                binding.SendTimeout = new TimeSpan(0, 10, 0);  
                binding.ReceiveTimeout = new TimeSpan(0, 10, 0);  

                serviceHost.AddServiceEndpoint("ICalculator", binding, baseAddress);  
                serviceHost.Open();  

                // The service can now be accessed.  
                Console.WriteLine("The service is ready.");  
                Console.WriteLine("Press <ENTER> to terminate service.");  
                Console.WriteLine();  
                Console.ReadLine();  

            }  
            catch (CommunicationException ex)  
            {  
                // Handle exception ...  
            }  
        }