Debug a RIA Service from Silverlight project

If you need to debug a Silverlight project that references a RIA Service project that host the Entity Framework mapping with the Data Access Layer logic, you need to insert inside the App.config file in the RIA Service this xml node

<system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
    <httpModules>
      <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </httpModules>
</system.web>
Advertisements

Forward parameters from Silverlight Web project to Silverlight project

In “real-world” is really common that your Silverlight application needs some parameters from the relatieve Web project.
If you have the necessity to pass some parameters, never mind.
You can use this trick.
For istance, you need to pass the HttpContex from the Silverlight Web to the relatieve Silverlight project.
You can add in default.aspx page in SL Web this tag:

<param name="initParams" value="username=<%=HttpContext.Current.User.Identity.Name%>" />

Then, you need to add in App.xaml.vb page (inside the constructor) this code

If Not e.InitParams Is Nothing Then
      For Each data As Object In e.InitParams
          Me.Resources.Add(data.Key, data.Value)
      Next
End If

In this way you add this resources to the Resources dictionary in SL project.
Then, at the end, you can retrieve the resource key property to obtain the relatieve value

Dim user As String = App.Current.Resources("username").ToString()

If you need to pass more than one parameter, add in the same tag “initParams” all the parameters you need and separate them with commas.
For example,

<param name="initParams" value="param1=value1,param2=value2" />