Friday, March 16, 2012 4:30 PM
I have written a service to manage session variables like this.
Imports System.ServiceModel Imports System.ServiceModel.Activation <ServiceContract(Namespace:="")> <SilverLightFaultBehavior()> <AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> Public Class SessionService <OperationContract()> Public Sub DoWork() ' Add your operation implementation here End Sub ' Add more operations here and mark them with <OperationContract()> <OperationContract()> Public Function GetSessionVariable(key As String) As Object Return System.Web.HttpContext.Current.Session(key) End Function <OperationContract()> Public Sub PutSessionVariable(key As String, value As Object) System.Web.HttpContext.Current.Session(key) = value End Sub End Class
This seems to work, but my first question is does it look correct in all respects?
Secondly, I have added a service reference in my silverlight project. I found that when I used the default address (localhost) for the reference, it would work in development but not when I published it. So I changed the address to refer directly to the production server. IE. \\myserver\myproject\Services\myservice
With this change it works on the production server but when run on the development box it references the session on the main server and not the session on the development server. While I understand this, since the reference is to the production server, it seems goofy to have to reconfigure the service everytime I publish the project. Is there something I have missed that will allow me to configure it once and forget it?
Friday, March 16, 2012 6:31 PM
Since you're using WCF which rely on the ClientConfig file embedded in the XAP file you'll need to reconfig it everytime you deploy. Switch to WCF RIA Services will eliminate that issue.
Monday, March 19, 2012 3:43 PM
Thanks G20. Is there an easy way to convert my project to use RIA services? All the samples I can find start with RIA at the outset. What do I need to make the switch?
Monday, March 19, 2012 8:33 PM
I don't think there is a turn-key way to convert WCF to WCF-RIA Service.
Most of the work will be done on the Silverlight client side where you'll need to replace all calls to WCF methods with the equivalent methods from the RIA data context. But most of the code will be must simpler especially the update/insert entity code since you don't need to use the update/insert methods that you had to implement in WCF implementation.
On the server, at the begin, you'll need to create the entity model from your database (or you can create the model and then database if you don't have the db defined yet), then create the Domain Service which is the foundation of the RIA Service and start using it in the Silverlight client portion.
Good luck with the conversion.