ViewState in WebService? Is it possible?

according to my research, this is not possible ... unless I write one big hack (erk) to get around it ... they are wondering if this is possible or not, as some of you may have more information about this, I understand that this will run counter to the page paradigm, however it really needs to be accessible ... any ideas from anyone?

they hate the use of cookies because the information is updated and reflects the real values ​​in the collection after full rounding (so there is always one round trip) ... im just storage the array really ... session can be used in webservices but really don't want to load the server is too much, although its probably only half kb ... maybe it is too paranoid?

any advice would be appreciated if it is worth not to use the session state currently using cookies, prefers to use viewstate, thanks.

+4
source share
5 answers

just create an array of cache objects in the session object :). The cache cache should also free the session from memory :)

+1
source

Why not use the application cache? It works great for this purpose.

public static void AddToCache(string key, Object value, int slidingMinutesToExpire) { if (slidingMinutesToExpire == 0) { HttpRuntime.Cache.Insert(key, value, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.NotRemovable, null); } else { HttpRuntime.Cache.Insert(key, value, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(slidingMinutesToExpire), System.Web.Caching.CacheItemPriority.NotRemovable, null); } } 
+3
source

No, you cannot use ViewState with web services. ViewState requires a hidden <input> field and HTTP post-postback. Input fields are not supported by web services.

Since ViewState requires encoding data and sends it to the client and vice versa, it is no more efficient than cookies that are supported by web services because they are implemented at the protocol level and not as part of HTML, such as ViewState.

Alternatively, you can use session state and store information on the server.

+2
source

No, Viewstate is closely related to using the browser as an HTTP client.

For web services, you have two options: let the client monitor the status of the conversation or let the server monitor it.

  • Using server session state and passing a cookie (either an HTTP cookie or some kind of cookie inside a SOAP envelope)

  • the client needs to monitor, save, and possibly transmit the state of the conversation to the server.


About Viewstate is the state of the page presented to the user, and as an implementation, it is closely related to the browser. When a page is displayed, browsing information is used to populate the page. Later, when the form is placed on the page, the corresponding form data is then transferred to the server, some of which may have been set using the viewstate magic. The server needs to check the client input despite using the viewstate on the client side. You can see that the viewstate combined with some lightweight population logic on the browser side is a way for the client to control the state of the page the user sees, but the server cannot refuse to check the status of the conversation.

This approach can be applied in a web services application, but since it does not depend on the browser or on a specific presentation (or generally on any presentation), this is a do-it-yourself matter. The client application maintains and uses any dialog state in a way that is suitable for the client.

On the other hand, server-managed state means that each "session" or "session" stores state information stored on the server. The client does not have to track information if the server does this. The client simply presents the token (or cookie, if you want) to the server, and the server uses it as a search key in the status table. The server is primarily responsible for checking the entire state stored on behalf of the client.

Since you are using .NET, you might be interested to know that the workflow can be used on the server side to monitor the status of web services (WCF) . This approach supports WS network protocols - it does not provide any specific client technologies or platforms.

0
source

You cannot use ViewState (or maybe after a lot of unnecessary hard work :) in a web service, but as an alternative you can use session state. Session status is enabled for each WebMethod using the EnableSession value:

 [WebMethod(EnableSession=true)] public int SessionHitCounter() { ... } 

Read more here on MSDN.

0
source

All Articles