繁体   English   中英

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

[英]Increase C# class library(DLL) Timeout calling wcf service

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

我在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。

您需要在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 ...  
            }  
        }

暂无
暂无

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

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