开发者

Can we not have member variables in RIA services?

开发者 https://www.devze.com 2023-02-17 13:50 出处:网络
I created a simple RIA Service on my server side and created it\'s respective context on the client. I have few 2 [Invoke] operations in my RIA se开发者_开发百科rvices. In the 1st call, I call the 1st

I created a simple RIA Service on my server side and created it's respective context on the client. I have few 2 [Invoke] operations in my RIA se开发者_开发百科rvices. In the 1st call, I call the 1st method and set one private instance level variable. However when i call the 2nd method the variable no longer retains the value. It becomes null. Why does it happen so? I already have the same DomainContext on the client for both the method calls, then why is this happening? Is it prohibited to have any instance variable in RIA service?

Thanks in advance :)


You cannot have private members in this scenario because the instances of your DomainContext between the two invokes are actually separate objects. Every call is being made atomically and the server portion creates and cleans up the object after use.

One option is to shift the stateful nature of your calls from the server to the client. Have the first method return as a concrete class a model which encapsulates the private values you wish to track. You can then use that model in the client to invoke the second instance method. If you do not want this data over the wire then this is not a good option.

A second option is to simply leverage the Session or Cache objects of ASP.NET Since Silverlight does run under the ASP.NET context. HttpContext.Current is available to your services and coupled to the user.

Another option is to simply chain both methods into a single invoke method.

0

精彩评论

暂无评论...
验证码 换一张
取 消