【问题标题】:WCF in Silverlight - how to set change the default timeout of 1 minuteSilverlight 中的 WCF - 如何设置更改默认超时 1 分钟
【发布时间】:2013-06-24 10:28:05
【问题描述】:

我在 Silverlight 项目中连接到 WCF 服务。服务需要完成的任务需要一分钟(这很好),但我收到一个错误。我通过代理与它通信(由 dev studio 在您添加服务引用时创建)

The HTTP request to 'http://localhost/ImporterService.svc' has exceeded the allotted timeout. The time allotted to this operation may have been a portion of a longer timeout.

(其中 ImporterService 是我的服务)

在过去的 3 天里,我已经阅读了各种关于增加以下内容的帖子。

receiveTimeout="00:10:00"
sendTimeout="00:10:00"
openTimeout="00:10:00"
closeTimeout="00:10:00"

没有任何效果,1分钟后仍然超时!

好的,所以在生成的文件 ServiceReferences.ClientConfig 中,我在以下位置添加了值

<configuration>
  <system.serviceModel>
  <bindings>
   <basicHttpBinding>
   <binding name="BasicHttpBinding_ImporterService" maxBufferSize="2147483647"
      receiveTimeout="00:10:00"
      sendTimeout="00:10:00"
        openTimeout="00:10:00"
        closeTimeout="00:10:00"
        maxReceivedMessageSize="2147483647">
        <security mode="None" />
        </binding>
        ....

此超时似乎发生在客户端(例如,我可以通过在服务代码中添加 1 分钟睡眠来实现)

问题1 所以,就我而言,我需要改变的只是客户端。

无论如何在 web.config 中 在 web.config 中,我添加了块

inside the existing <basicHttpBinding> as shown below


 ><basicHttpBinding>
    ><binding name="downloadBinding" maxReceivedMessageSize="2000000" maxBufferSize="2000000">
    ><readerQuotas maxArrayLength="2000000" maxStringContentLength="2000000" />
    ></binding>
    >    
    ><binding name="BasicHttpBinding_IImporterService" maxBufferSize="2147483647"
    >receiveTimeout="00:10:00"
    >sendTimeout="00:10:00"
    >openTimeout="00:10:00"
    >closeTimeout="00:10:00"
    >maxReceivedMessageSize="2147483647">
    ><security mode="None" />
    ></binding>
    >    
    ></basicHttpBinding>            
    ></bindings>

请注意,我使用的是 BasicHttpBinding_IImporterService 名称(其他帖子使用了随机名称,它们在客户端和服务器上甚至都不相同!例如

I also have <httpRuntime executionTimeout set to a huge value.

超时只是没有增加。还有 1 分钟。

所以,大问题

1. What an I doing wrong, am I putting these settings in the wrong place?
2. Is it just client side I need to do
3. Perhap it can be done in code if these config settings don't work

例如,在我使用它的地方,我使用它进行实例化

ImporterServiceClient importerService = new ImporterServiceClient("*", new &gt;EndpointAddress(ServicePath));

我知道还有很多其他帖子,但是,大多数只包含属性,而不是确切的设置位置,所以很明显我的位置错误?

任何帮助将不胜感激。我想做的就是增加超时时间(在代码、配置、任何实际工作的地方)!

提前感谢任何可以在这里提供帮助的人 皮特

【问题讨论】:

    标签: wcf silverlight timeout


    【解决方案1】:

    @Std_Net,非常感谢您的回复。在我发布这篇文章后不久,我设法让它工作了(虽然我已经挣扎了几天!)

    以上正是我添加超时设置的内容,由于某种原因,该设置对我来说并不适用。我找到了一个示例,其中这些是在代码中设置的,当我尝试时,它们似乎终于可以工作了。

    你是对的,我不需要在服务器站点(web.config)上做任何事情,只需要客户端。

    以防万一其他人需要知道这一点(即像我这样的 WCF 新手),这至少对我有用...

    私有只读 ImporterServiceClient m_importerService; ...

    m_importerService = new ImporterServiceClient("*", new EndpointAddress(ServicePath));            
    const int timeoutMinutes = 15;
    m_importerService.Endpoint.Binding.OpenTimeout = TimeSpan.FromMinutes(timeoutMinutes);
    m_importerService.Endpoint.Binding.SendTimeout = TimeSpan.FromMinutes(timeoutMinutes);
    

    【讨论】:

      【解决方案2】:

      在 web.config 中无需添加任何超时数据。 将超时设置添加到您的 SL 应用程序。 当您将 ServiceRefferences 添加到项目中时,VisualStudio 必须生成文件

      ServiceReferences.ClientConfig

      我有这个配置

      <?xml version="1.0" encoding="utf-8"?>
      
      <configuration>
          <system.serviceModel>
              <bindings>
                  <basicHttpBinding>
      
                  <binding name="BasicHttpBinding_IEventsService" closeTimeout="01:59:00"
                      receiveTimeout="01:59:00" sendTimeout="01:59:00" maxBufferSize="2147483647"
                      maxReceivedMessageSize="2147483647">
                      <security mode="None" />
                  </binding>
              </basicHttpBinding>
          </bindings>
          <client>
              <endpoint address="http://mySite/MyService.svc"
                  binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IEventsService"
                  contract="EventService.IEventsService" name="BasicHttpBinding_IEventsService" />
      
          </client>
      </system.serviceModel>
      

      您可以根据需要设置超时参数。 希望对您有所帮助。

      【讨论】:

        猜你喜欢
        • 2011-01-15
        • 1970-01-01
        • 2019-01-06
        • 2023-01-06
        • 2010-10-23
        • 2018-08-26
        • 1970-01-01
        • 1970-01-01
        • 2017-03-07
        相关资源
        最近更新 更多