如何使同步RIA请求 [英] How to make synchronous RIA request

查看:139
本文介绍了如何使同步RIA请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的RIA服务,我想有一个非常简单的打电话找允许某个自定义对象的最大领域。该值将不经常更新的,如果有的话,我想在需要时调用它只是一次,然后保持它在客户端上。然而,当我需要知道的价值,我需要知道它以同步的方式,因为我将使用它的时候了。

I have an existing RIA service in which I would like to include a very simple call to find the maximum fields allowed for a certain custom object. The value will change infrequently, if ever, and I would like to call it just once when needed and then keep it on the client. However, when I need to know the value, I need to know it in a synchronous manner, as I will be using it right away.

我已经试过以下,但。价值永远只是0,因为该服务实际上并没有做出请求时的code此块运行时,而是一段时间后。

I've tried the following, but the .Value is always just 0, since the service doesn't actually make the request when this block of code is run, but rather sometime later.

private static readonly Lazy<int> _fieldCount =
    new Lazy<int>(() =>
        {
            const int TotalWaitMilliseconds = 2000;
            const int PollIntervalMilliseconds = 500;

            // Create the  context for the RIA service and get the field count from the server.
            var svc = new TemplateContext();
            var qry = svc.GetFieldCount();

            // Wait for the query to complete. Note: With RIA, it won't.
            int fieldCount = qry.Value;
            if (!qry.IsComplete)
            {
                for (int i = 0; i < TotalWaitMilliseconds / PollIntervalMilliseconds; i++)
                {
                    System.Threading.Thread.Sleep(PollIntervalMilliseconds);
                    if (qry.IsComplete) break;
                }
            }

            // Unfortunately this assignment is absolutely worthless as there is no way I've discovered to really invoke the RIA service within this method.
            // It will only send the service request after the value has been returned, and thus *after* we actually need it.
            fieldCount = qry.Value;

            return fieldCount;
        });

有没有的任意的方法,使使用RIA服务同步,负载点播服务电话?或将我不得不采取:1)包括在客户端code中的常数,推出更新当/如果有史以来它的变化;或2)举办一个完全独立的服务,我可以以同步的方式调用?

Is there any way to make a synchronous, load-on-demand service call using RIA services? Or will I have to either: 1) include the constant in the client code, and push out update when/if-ever it changes; or 2) host a completely separate service, which I can call in a synchronous fashion?

推荐答案

您不能让WCF RIA同步工作,很遗憾。你可以做的是放在 initParams在&LT的价值;对象&gt; HTML标记承载Silverlight的。了解更多: http://msdn.microsoft.com /en-us/library/cc189004(v=vs.100).aspx

You cannot make WCF RIA work synchronously, unfortunately. What you can do is put the value in the InitParams of the <object> tag in the HTML that hosts the Silverlight. Read more: http://msdn.microsoft.com/en-us/library/cc189004(v=vs.100).aspx

这篇关于如何使同步RIA请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆