从异步WCF双工通话更新asp.net页面 - 对象范围 - ASP.NET [英] Updating the asp.net page from the asynchronous WCF duplex call - object scope - ASP.NET

查看:224
本文介绍了从异步WCF双工通话更新asp.net页面 - 对象范围 - ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下疑问。我有一个页面我的页面我已经声明在页面几类字典对象。

I've the following doubt. I've a page "MyPage" and i've declared few dictionary objects in the page class.

我的疑问是


  1. 如果我宣布字典作为民办非静态对象我不能在页面类使用它跨职能(对象是越来越调零)

  2. 但是,如果我宣布字典是静态的我能够跨跨职能的对象。但该对象在所有谁现在已打开页面的用户相同的(猜测每个用户将在翻开新的一页的一个实例已一类的页面类和静态变量的一个实例是在所有情况下不变之类的)

我的理解是正确的?如何申报对象进行跨页类中的所有可用的功能和独特的页面(用户)的每个实例。

Is my understanding right? How to declare the object to be available across all the functions within the page class and unique for each instance of the page (user).

UPDATE1

奥基,我发现在页面类字典对象的初始化在不同的线程(WCF双工回调)完成。但在主页主题字典对象仍然保留为空(初始化)。有任何想法吗?

Okie, i find that the initialization of the dictionary object in the page class is done in a different thread (WCF Duplex callback). But in the main page thread the dictionary object is still remaining as null (uninitialized). Any ideas?

UPDATE2

编组站 - 有用的任何机会。

Marshalling - useful by any chance?

UPDATE3

在回答约翰 -

感谢您的答复。我面对现在的问题是在客户端(这将在一个单独的线程调用的)的asp.net页面传递从WCF回调类的数据。那么,如何能做到这一点?视图状态可以帮助我坚持跨请求的数据。但是,当回调被服务器通知一变调用我应该如何通过改变(数据)到UI线程(asp.net页面)?

Thanks for your reply. The problem i'm facing now is to pass the data from the WCF callback class at the client side(which will be invoked in a separate thread) to the asp.net page. So how can i do that? View state may help me to persist the data across requests. But when the callback is invoked by the server notifying for a change how should i pass the changes (data) to the UI thread (asp.net page)?

推荐答案

不要做这样的事情。

如果您需要在页面之间保持数据,使用会话状态。这就是它是。你应该记住,你得到你的页面类的新实例在每次请求。不要使用静态保持后续请求周围不断变化的数据。你可能会进入一个与多个请求同时更新数据的麻烦。

If you need to maintain data between pages, use Session state. That's what it's for. You should remember that you get a new instance of your page class on every request. Do not use statics to keep changing data around for subsequent requests. You will probably get into trouble with multiple requests updating the data at the same time.

您不能这样的事情在ASP.NET!

You can't do things like this with ASP.NET!

您似乎这当作好像是一个桌面程序 - 就好像你的类实例和所有国家仍然会在那里等你下一次执行页面上的方法。这是不正确的 - 请求完成后,你的页面将被全部销毁。有关页面没有将仍然有效。

You seem to be treating this as though it were a desktop program - as though your class instance and all state will still be there for you next time you execute a method on the page. That's not true - when the request is complete, your page will be Disposed. Nothing about the page will remain valid.

在特定的,如果请求结束前回调不会发生,然后回调方法最好不要参考不得不做的要求,如你的页面东西。这是因为回调可能被激活的之后的请求已经结束了!该州已损坏或更糟。

In particular, if the callback doesn't happen before the request ends, then the callback method had better not reference anything having to do with the request, like your page. That's because the callback might fire after the request is already over! The state is corrupt or worse.

除非你打算在页面等待回调,你真的最好不要在你的网页中使用它们。相反,创建一个单独的Windows服务或东西,有它发出请求,并等待回调。那么页面可以使用Ajax或东西问,如果请求完成,并获得响应一次完成。

Unless you are going to have the page wait for the callback, you'd really better not use them in your pages. Instead, create a separate Windows Service or something and have it issue the requests and await the callback. The page can then use Ajax or something to ask if the request is complete, and to get the response once complete.

如果你认为你听到我说要回调用一个ASP.NET页面,那么你误会了。

If you think you heard me say to call back to an ASP.NET page, then you misunderstood.

创建一个Windows服务。您的Windows服务将举办WCF服务的ASP.NET应用程序将要。 WCF服务将跟踪之类的东西谁是加入了聊天,谁的打字等。

Create a Windows Service. Your Windows Service will host a WCF service that the ASP.NET application will talk to. The WCF Service will keep track of things like who's joined a chat, who's typing, etc.

Web应用程序的无法的时候进行一些有趣的情况通报。取而代之的是,Web应用程序将轮询WCF服务,询问什么有趣的事情发生了。当有事情发生,WCF服务将通过东西回ASP.NET应用程序(或可能,回页面,通过AJAX调用)。

The web application cannot be notified when something interesting happens. Instead, the web application will have to poll the WCF service, asking if anything interesting has happened. When something happens, the WCF service will pass the "something" back to the ASP.NET application (or possibly, back to the page, called by AJAX).

我前面说错。你根本无法在这种情况下使用回调合同都没有。它不喜欢的网页就像一个桌面应用程序,每个用户一个,等待通知。它们更像是在哪里,当用户发出请求时,你把他的电脑,并给他一个新的,就像它的桌面应用程序,响应到达之前。

I misspoke earlier. You simply cannot use a callback contract at all in this situation. It's not like the web pages are like a desktop application, one per user, waiting to be notified. They're more like a desktop application where, when the user makes a request, you take his PC and give him a new one just like it, before the response arrives.

这篇关于从异步WCF双工通话更新asp.net页面 - 对象范围 - ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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