RIA服务WCF超时

3

我有一个应用程序,它使用Silverlight 3.0编写。它使用RIA服务在客户端和服务器之间进行通信。

我的问题在网络上似乎没有得到很好的回答。客户端使用RIA服务与服务器通信,该服务在幕后使用WCF。如果通信时间超过60秒,则会出现以下错误消息:

“查询'ApplyUpgrade'的加载操作失败。到'http://localhost:52403/ClientBin/DatabaseUpgradeTool-Web-UpgradePackageDomainService.svc/binary'的HTTP请求已超过分配的超时时间。此操作所分配的时间可能是更长时间的一部分。”

我的服务器正在执行数据库升级,因此它需要花费比60秒更长的时间。可能是两倍或三倍。

我在web.config中尝试了以下设置:

<services>
    <service name="DatabaseUpgradeTool.Web.UpgradePackageDomainService">
      <endpoint address="" binding="wsHttpBinding" contract="DatabaseUpgradeTool.Web.UpgradePackageDomainService"></endpoint>
      <endpoint address="/soap" binding="basicHttpBinding" contract="DatabaseUpgradeTool.Web.UpgradePackageDomainService"></endpoint>
      <endpoint address="/binary" binding="customBinding" bindingConfiguration="BinaryHttpBinding" contract="DatabaseUpgradeTool.Web.UpgradePackageDomainService"></endpoint>
    </service>
  </services>
<bindings>
    <customBinding>
      <binding name="BinaryHttpBinding"
               receiveTimeout="00:00:10"
               sendTimeout="00:00:10" 
               openTimeout="00:00:10" 
               closeTimeout="00:00:10">
        <binaryMessageEncoding   />
        <httpTransport keepAliveEnabled="true"/>
      </binding>
    </customBinding>
  </bindings>

仍然没有成功。你有任何想法,关于我所尝试的方法有什么问题吗?我期望它在10秒内超时,而不是60秒。

谢谢。


请注意上面更新的问题。我尝试了一些在web.config中的设置,但它们并没有生效。这可能会引发其他的想法。 - peter
请查看同样的问题 - Timores
2个回答

0

我遇到了同样的问题,我在这里发布了答案:Silverlight 4 WCF RIA服务超时问题

以下是答案:

我将解释我的背景,并希望它适用于我。我对此非常确定。

首先,要调用RIA服务并使用一些域上下文,在我的示例中:

EmployeeDomainContext context = new EmployeeDomainContext();
InvokeOperation<bool> invokeOperation = context.GenerateTMEAccessByEmployee(1, 'Bob');
invokeOperation.Completed += (s, x) =>
    {....};

到这里没有什么新的。每次都会在1分钟后遇到相同的超时异常。我花了很多时间试图面对如何更改超时定义,我试了Web.config中所有可能的更改,但都没有成功。 解决办法是:

创建一个CustomEmployeeDomainContext,它是一个局部类,位于生成代码的相同路径中,并且该类使用OnCreate挂钩方法来更改创建域上下文的行为。 在该类中,您应该编写以下内容:

public partial class EmployeeDomainContext : DomainContext
{
    partial void OnCreated()
    {
        PropertyInfo channelFactoryProperty = this.DomainClient.GetType().GetProperty("ChannelFactory");
        if (channelFactoryProperty == null)
        {
            throw new InvalidOperationException(
              "There is no 'ChannelFactory' property on the DomainClient.");
        }

        ChannelFactory factory = (ChannelFactory)channelFactoryProperty.GetValue(this.DomainClient, null);

        factory.Endpoint.Binding.SendTimeout = new TimeSpan(0, 10, 0); 

    }
}

我期待着您的反馈。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接