【问题标题】:Increase C# class library(DLL) Timeout calling wcf service增加C#类库(DLL)调用wcf服务超时
【发布时间】:2018-04-06 03:04:52
【问题描述】:

我有一个调用 WCF 服务的类库。完成这项服务大约需要 3 分钟。我正在使用 Windows 窗体,并在 httpRuntime 元素的 App.Config 中添加了 executionTimeout。尽管如此,它不会等到它完成交易。如何延长通话等待时间?

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

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

我点击下面的按钮调用我的服务。

Registration rObj = new Registration("http://x.x.x.x:1010/Service.svc");
RegInfo sObj = rObj.ValidateRegistration("1234");
MessageBox.Show(sObj.bIsRegistered.ToString());

但是当请求响应时间有点长时,上面会调用 TimesOut。

【问题讨论】:

  • 您是否在客户端设置了超时?我看不到。
  • 我也为客户设置了 6 分钟

标签: c# winforms wcf timeout class-library


【解决方案1】:

您需要在 WCF 应用程序和 Windows 窗体应用程序上设置超时

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

=> 第一次更改

<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>

=> 第二个变化:增加 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 ...  
            }  
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-03
    • 2016-07-24
    • 1970-01-01
    • 1970-01-01
    • 2014-03-31
    • 2013-12-02
    • 2012-12-07
    • 1970-01-01
    相关资源
    最近更新 更多