<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>With Great Power comes Great Response.write("Ability") : Silverlight</title><link>http://blogs.msdn.com/phaniraj/archive/tags/Silverlight/default.aspx</link><description>Tags: Silverlight</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Using the ADO.NET Data Services Silverlight client library in x-domain and out of browser scenarios – II (Forms Authentication)</title><link>http://blogs.msdn.com/phaniraj/archive/2009/09/10/using-the-ado-net-data-services-silverlight-client-library-in-x-domain-and-out-of-browser-scenarios-ii-forms-authentication.aspx</link><pubDate>Thu, 10 Sep 2009 02:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9893382</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9893382.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9893382</wfw:commentRss><description>&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;A href="http://blogs.msdn.com/phaniraj/attachment/9893382.ashx" mce_href="http://blogs.msdn.com/phaniraj/attachment/9893382.ashx"&gt;Click here to download sample application&lt;/A&gt;&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using the ADO.NET Data Services Silverlight client library in x-domain and out of browser scenarios – II (Forms Authentication) &lt;BR&gt;In this blog post, we will talk about using the Silverlight Client Library against a Data Service that is secured with Asp.Net Forms Authentication &lt;BR&gt;In short, the whole process of authenticating against a Forms Authentication protected Data Service looks like this. &lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_8.png" mce_href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_8.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_thumb_3.png" width=729 height=303 mce_src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_thumb_3.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;H3&gt;Server Setup &lt;/H3&gt;
&lt;OL&gt;
&lt;LI&gt;Setup Forms Authentication on the Data Service Server &lt;/LI&gt;
&lt;LI&gt;Enable the WCF Authentication Service by following the reference here : &lt;A href="http://msdn.microsoft.com/en-us/library/bb398990.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb398990.aspx"&gt;How to: Enable the WCF Authentication Service&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;Exclude the following resources from requiring authentication , &lt;/LI&gt;&lt;/OL&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;3.1 The WCF Authentication Service &lt;BR&gt;3.2 The ClientAccessPolicy.xml File &lt;BR&gt;Ex:&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=rem&gt;&amp;lt;!-- The ClientAccessPolicy.xml file is required for the client to confirm if the server allows X-Domain callers.&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;       This should be downloadable without authenticating--&amp;gt;&lt;/SPAN&gt;
 &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;location&lt;/SPAN&gt; &lt;SPAN class=attr&gt;path&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="clientaccesspolicy.xml"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.web&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
      &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;authorization&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;allow&lt;/SPAN&gt; &lt;SPAN class=attr&gt;users&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="*"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
      &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;authorization&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.web&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;location&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
 &lt;SPAN class=rem&gt;&amp;lt;!--This should be downloadable without authenticating.--&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;location&lt;/SPAN&gt; &lt;SPAN class=attr&gt;path&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="AuthenticationService.svc"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.web&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
      &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;authorization&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;allow&lt;/SPAN&gt; &lt;SPAN class=attr&gt;users&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="*"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
      &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;authorization&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.web&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;location&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;4. If the DataServiceHost does not have a global.asax file, add one to the project. &lt;BR&gt;5. In the Global.asax file, we need to listen on the &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.applicationservices.authenticationservice.creatingcookie.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.applicationservices.authenticationservice.creatingcookie.aspx"&gt;AuthenticationService.CreatingCookie&lt;/A&gt; event to customize the FormsAuth Cookie that the service creates.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Why do we need to customize the FormsAuth cookie? &lt;BR&gt;&lt;/B&gt;The WCF Authentication service by default creates &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.httpcookie.httponly.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.httpcookie.httponly.aspx"&gt;HTTPOnly&lt;/A&gt; Cookies. &lt;BR&gt;This means that the cookie isn’t accessible by client-script. &lt;BR&gt;It generally isn’t a problem when the client application is running in the same domain as the Website, &lt;BR&gt;as the browser handles cookie management for us transparently. &lt;BR&gt;When the client is not in the same domain as the Website, and we use the ClientHttpWebRequest networking stack, &lt;BR&gt;we are unable to access any cookies marked as HttpOnly. &lt;BR&gt;To work around this limitation, we recreate the FormsAuth cookie with HttpOnly set to false in the CreatingCookie event handler. &lt;BR&gt;For more details: &lt;A href="http://msdn.microsoft.com/en-us/library/bb398778.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb398778.aspx"&gt;How to: Customize the Authentication Cookie from the WCF Authentication Service&lt;/A&gt; &lt;BR&gt;Example code:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Application_Start(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, EventArgs e)
{
&lt;SPAN class=rem&gt;//Handle the CreatingCookie event so that we can create a custom cookie with HttpOnly set to false.&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;//AuthenticationService.CreatingCookie on MSDN :&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;//http://msdn.microsoft.com/enus/library/system.web.applicationservices.authenticationservice.creatingcookie.aspx&lt;/SPAN&gt;
AuthenticationService.CreatingCookie += &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; EventHandler&amp;lt;CreatingCookieEventArgs&amp;gt;(CreateSilverlightCompatibleHttpCookie);
}&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=rem&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// Creates a HttpCookie that can be read by the managed CookieContainer in ClientHttpWebRequest in Silverlight&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;param name="sender"&amp;gt;The calling context for this event&amp;lt;/param&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;param name="e"&amp;gt;a property bag containing useful information about the HttpCookie to create&amp;lt;/param&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; CreateSilverlightCompatibleHttpCookie(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, System.Web.ApplicationServices.CreatingCookieEventArgs e)
{
  &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; cookieVersion = 1;
  &lt;SPAN class=rem&gt;//The time at which the cookie was issued by the server&lt;/SPAN&gt;
  DateTime cookieIssueDate = DateTime.Now;
  &lt;SPAN class=rem&gt;//The relative time from now when the cookie will expire and the client will have to re-authenticate.&lt;/SPAN&gt;
  DateTime cookieExpiryDate = DateTime.Now.AddMinutes(30);
  &lt;SPAN class=rem&gt;//The Forms Auth ticket which uniquely identifies a user &lt;/SPAN&gt;
  &lt;SPAN class=rem&gt;//FormsAuthenticationTicket on MSDN : http://msdn.microsoft.com/en-us/library/system.web.security.formsauthenticationticket.aspx&lt;/SPAN&gt;
  FormsAuthenticationTicket ticket = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; FormsAuthenticationTicket
                (cookieVersion,
                 e.UserName,
                 cookieIssueDate,
                 cookieExpiryDate,
                 e.IsPersistent, &lt;SPAN class=rem&gt;/*Indicates whether the authentication cookie should be retained beyond the current session*/&lt;/SPAN&gt;
                 e.CustomCredential,
                 FormsAuthentication.FormsCookiePath);
 &lt;SPAN class=rem&gt;//Creates a string containing an encrypted forms-authentication ticket suitable for use in an HTTP cookie.&lt;/SPAN&gt;
 &lt;SPAN class=rem&gt;//FormsAuthentication.Encrypt on MSDN : http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.encrypt.aspx&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; encryptedTicket = FormsAuthentication.Encrypt(ticket);
  HttpCookie cookie = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
  &lt;SPAN class=rem&gt;//set HttpOnly to false so that the managed CookieContainer can read the FormsAuth cookie from the response.&lt;/SPAN&gt;
  cookie.HttpOnly = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
  cookie.Expires = cookieExpiryDate;
  HttpContext.Current.Response.Cookies.Add(cookie);
  e.CookieIsSet = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
 }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;H3&gt;Silverlight Client Setup&lt;/H3&gt;
&lt;P&gt;We will follow an adapter pattern which is responsible for logging in the user and injecting the FormsAuth cookie as the client library makes requests. &lt;BR&gt;To start with,&lt;B&gt; add a Service reference to the WCF Authentication service in the Silverlight Client application or use the one in the sample.&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;The FormsAuthAdapter will use the client side proxy generated for the WCF Authentication service to login the user &lt;BR&gt;and hook into any attached DataServiceContext instance’s SendingRequest event to inject the FormsAuth cookie. &lt;BR&gt;An instance of the FormsAuthenticationAdapter is declared at the application level.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;partial&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; App : Application
{
&lt;SPAN class=rem&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// FormsAuthenticationAdapter instance to manage authentication against a WCF Authentication Service&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;static&lt;/SPAN&gt; FormsAuthenticationAdapter FormsAuthAdapter;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;This is initialized when the Application starts.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Application_Startup(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, StartupEventArgs e)
{
&lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; authServiceUri = String.Empty;
&lt;SPAN class=rem&gt;//extract the AuthenticationService Uri from the App.XAML file&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (&lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.Resources.Contains(&lt;SPAN class=str&gt;"AuthenticationServiceUri"&lt;/SPAN&gt;))
{
authServiceUri = &lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.Resources[&lt;SPAN class=str&gt;"AuthenticationServiceUri"&lt;/SPAN&gt;].ToString();
}
FormsAuthAdapter = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; FormsAuthenticationAdapter(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Uri(authServiceUri, UriKind.RelativeOrAbsolute));
&lt;SPAN class=rem&gt;//The FormsAuthCookieName  should be the same value as declared in the Web.config of the server&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;//ex: If your web.config on the server requiring Forms Authentication is :&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;//&amp;lt;authentication mode="Forms"&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;//  &amp;lt;forms loginUrl="LoginForm.aspx" name=".ASPXFormsAUTH" protection="All" path="/" /&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;//&amp;lt;/authentication&amp;gt;&lt;/SPAN&gt;
    FormsAuthAdapter.FormsAuthCookieName = &lt;SPAN class=str&gt;".ASPXFormsAUTH"&lt;/SPAN&gt;;
    &lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.RootVisual = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MainPage();
    &lt;SPAN class=rem&gt;//Uncomment the below 2 lines to show the Loginwindow on application startup&lt;/SPAN&gt;
    &lt;SPAN class=rem&gt;//LoginWindow login = new LoginWindow();&lt;/SPAN&gt;
    &lt;SPAN class=rem&gt;//login.Show();&lt;/SPAN&gt;
}&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;This is what our client application looks like: &lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_2.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_thumb.png" width=580 height=455 mce_src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;As you can see, along with the “Install me” button, we now have a “Login” button.&lt;/P&gt;
&lt;P&gt;When the page loads, we attach an instance of the DataServiceContext which we want to get the FormsAuth Cookie injected while &lt;BR&gt;making requests to the Data Service.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=rem&gt;//Attach the DataServiceContext instance so that we can inject the FormsAuth cookie for each request&lt;/SPAN&gt;
App.FormsAuthAdapter.Attach(publicationContext);
Where the Attach Method’s signature &lt;SPAN class=kwrd&gt;is&lt;/SPAN&gt; :
&lt;SPAN class=rem&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// Injects the FormsAuth cookie when the contextInstance makes a request to the DataService&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;param name="contextInstance"&amp;gt;The DataServiceContext instance to observe&amp;lt;/param&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Attach(DataServiceContext contextInstance)&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;Clicking the login button on the main page opens up a ChildWindow instance that we created which emulates the Login Screen. &lt;/P&gt;
&lt;P&gt;Login button click handler:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; LoginUser(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, RoutedEventArgs e)
{
    LoginWindow login = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; LoginWindow();
    login.Show();
    &lt;SPAN class=rem&gt;//The LoginWindow only closes if Authentication succeeds&lt;/SPAN&gt;
    login.Closing += (s, eArgs) =&amp;gt;
    {
       &lt;SPAN class=rem&gt;/*If auth succeeds,hide the button*/&lt;/SPAN&gt;
       btnLogin.Visibility = Visibility.Collapsed;
    };
  }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_6.png" mce_href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_6.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_thumb_2.png" width=582 height=429 mce_src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_thumb_2.png"&gt;&lt;/A&gt; &lt;BR&gt;The LoginWindow’s “Login” button uses the application wide FormsAuthenticationAdapter instance, discussed above, to login the user. &lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; LoginUser(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, RoutedEventArgs e)
{
App.FormsAuthAdapter.LoginAsync(txtUserName.Text, txtPassword.Password,
    (loginEventArgs) =&amp;gt;
    {
&lt;SPAN class=kwrd&gt;      if&lt;/SPAN&gt; (loginEventArgs.Result)
       {
         &lt;SPAN class=rem&gt;/*Login succeeded*/&lt;/SPAN&gt;
         &lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.DialogResult = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
       }
&lt;SPAN class=kwrd&gt;       else&lt;/SPAN&gt;
      {
         &lt;SPAN class=rem&gt;/*Login failed*/&lt;/SPAN&gt;
      }
    }
    );
}
The LoginAsync method’s signature &lt;SPAN class=kwrd&gt;is&lt;/SPAN&gt;:
  &lt;SPAN class=rem&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// Logs in the User and calls the LoginComplete handler&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;param name="userName"&amp;gt;UserName to login &amp;lt;/param&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;param name="passWord"&amp;gt;password for the user account&amp;lt;/param&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;param name="pLoginComplete"&amp;gt;Called when the login process is complete&amp;lt;/param&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; LoginAsync(&lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; userName, &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; passWord, Action&amp;lt;LoginCompletedEventArgs&amp;gt; pLoginComplete)&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;&lt;BR&gt;Once the user types in his/her username and password and hits “Login” , the Login window hits the WCF authentication service &lt;BR&gt;and extracts the FormsAuth cookie from the response.When the client library makes a request to the Data Service , the FormsAuthenticationAdapter &lt;BR&gt;injects the FormsAuth cookie &lt;/P&gt;
&lt;P&gt;&lt;B&gt;Common errors:&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;1. You receive an ArgumentException when trying to set the cookie header in the SendingRequest event.&lt;/P&gt;
&lt;P&gt;a. System.ArgumentException occurred &lt;BR&gt;&amp;nbsp; Message="The 'Cookie' header cannot be modified directly.\r\nParameter name: name" &lt;BR&gt;&amp;nbsp; StackTrace: &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at System.Net.WebHeaderCollection.ThrowOnRestrictedHeader(String name, String value) &lt;BR&gt;&amp;nbsp; InnerException: &lt;/P&gt;
&lt;P&gt;&lt;B&gt;Resolution: &lt;/B&gt;The reason you get this is because the client library is using the classic networking stack (based on XmlHttpRequest) &lt;BR&gt;to make the request. In this case, the Cookie header isn’t accessible and the above exception is valid. &lt;BR&gt;This is probably the only case where we would ask you to set the HttpStack property on the Client library. &lt;BR&gt;To fix this: &lt;BR&gt;//Set the HttpStack on the client Context instance to force the client library &lt;/P&gt;
&lt;P&gt;//to use the ClientHttpWebRequest stack for network access &lt;BR&gt;publicationContext.HttpStack = HttpStack.ClientHttp;&lt;B&gt; &lt;BR&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Additional resources:&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;How do I authenticate my users against the Active Directory from my Silverlight application? &lt;BR&gt;&lt;/B&gt;In ASP.NET Forms Authentication, the Membership provider is responsible for accessing the Credential store and validating the user name and password. &lt;BR&gt;By setting the Membership provider to be the ActiveDirectoryMembershipProvider , you can authenticate the user name and password the user enters &lt;BR&gt;with the credentials stored in Active Directory. For more details , please refer to this MSDN article :&lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ms998347.aspx#paght000022_usingtheactivedirectorymembershipprovider" mce_href="http://msdn.microsoft.com/en-us/library/ms998347.aspx#paght000022_usingtheactivedirectorymembershipprovider"&gt;Using the ActiveDirectoryMembershipProvider&lt;/A&gt; &lt;BR&gt;&lt;B&gt;References :&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd470115(VS.95).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd470115(VS.95).aspx"&gt;About ClientAccessPolicy.xml files&lt;/A&gt; &lt;BR&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb547119.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb547119.aspx"&gt;ASP.NET Application Services.&lt;/A&gt; &lt;BR&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/aa480476.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa480476.aspx"&gt;ASP.NET Forms Authentication&lt;/A&gt; &lt;BR&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/sx3h274z.aspx" mce_href="http://msdn.microsoft.com/en-us/library/sx3h274z.aspx"&gt;Membership Providers&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9893382" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/phaniraj/attachment/9893382.ashx" length="3537053" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Forms+Authentication/default.aspx">Forms Authentication</category></item><item><title>ADO.NET Data Services SL Client Library - XDomain and Out Of Browser</title><link>http://blogs.msdn.com/phaniraj/archive/2009/09/04/ado-net-data-services-sl-client-library-xdomain-and-out-of-browser.aspx</link><pubDate>Fri, 04 Sep 2009 05:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9891182</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9891182.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9891182</wfw:commentRss><description>&lt;P&gt;The first in my two part blog posts about&amp;nbsp;the new Silverlight Client Library we released in CTP2 is up on the team blog.&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=entrylistheader&gt;&lt;A id=bp___v___r___postlist___EntryItems_ctl01_PostTitle href="http://blogs.msdn.com/astoriateam/archive/2009/09/03/using-the-ado-net-data-services-silverlight-client-in-x-domain-and-out-of-browser-scenarios-i.aspx" mce_href="http://blogs.msdn.com/astoriateam/archive/2009/09/03/using-the-ado-net-data-services-silverlight-client-in-x-domain-and-out-of-browser-scenarios-i.aspx"&gt;Using the ADO.NET Data Services Silverlight client in x-domain and out of browser scenarios – I&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=entrylistheader&gt;Stay tuned to the team blog for the the second&amp;nbsp; part which talks about using the client library X-Domain and Out Of Browser&lt;BR&gt;to access a data service which is authenticated with Forms Authentication.&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9891182" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/CrossDomain/default.aspx">CrossDomain</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/DataServiceContext/default.aspx">DataServiceContext</category></item><item><title>Silverlight toolkit with ADO.NET Data services , Drill-down Charts using Astoria</title><link>http://blogs.msdn.com/phaniraj/archive/2009/06/11/silverlight-toolkit-with-ado-net-data-services-drill-down-charts-using-astoria.aspx</link><pubDate>Thu, 11 Jun 2009 10:12:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9726027</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9726027.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9726027</wfw:commentRss><description>&lt;p&gt;Download sample project here :&lt;/p&gt; &lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 26px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-925c2d2bb2d03c6b.skydrive.live.com/embedrow.aspx/SLToolkitAstoria/SLToolkitWithAstoria%7C_Chart%7C_DrillDown.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;In part 2 of this series , we will look at using the Astoria client library to create a drill down chart using the chart types available in the Silverlight toolkit.    &lt;br /&gt;You can take a look at the complete samples for the Silverlight toolkit &lt;a href="http://www.codeplex.com/Silverlight/Wiki/View.aspx?title=Silverlight%20Toolkit%20Overview%20Part%202&amp;amp;referringTitle=Silverlight%20Toolkit%20Overview%20Part%201"&gt;here&lt;/a&gt;.     &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;This sample builds a UI that looks like this :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Silverlighttoolk.NETDataservicesCharting_1428C/ChartDrillDownAstoria_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ChartDrillDownAstoria_2" border="0" alt="ChartDrillDownAstoria_2" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Silverlighttoolk.NETDataservicesCharting_1428C/ChartDrillDownAstoria_2_thumb.png" width="462" height="474" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The Pie chart represents the distribution of Employees across departments.    &lt;br /&gt;Clicking on a specific piece of the pie&amp;#160; brings up the list of the employees in that department.     &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Binding the Pie chart      &lt;br /&gt;&lt;/strong&gt;The Chart control has a Pie series that has the DependentValuePath set to the Count of employees in the department     &lt;br /&gt;and the IndependentValuePath set to the name of the department.&lt;/p&gt;  &lt;p&gt;Setting the IndependentValuePath is straightforward ,set the IndependentValuePath to the “DepartMentName” property of the Department entity type. The DependentValuePath is a little tricky , as the Department entity doesnt contain aggregation information regarding the employees in the Department . But , it does have the employees as an ObservableCollection of Employee types . So , we can get the count by assigning the DependentValuePath to be the expression “Employees.Count” which gets the Count property of the IList. Unfortunately ,&amp;#160; this means that the Employees will also have to be downloaded when you bind the Departments. In another post , I will discuss how to lazy load the employees list and still get this aggregation.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;XAML for Pie Series in Chart &lt;/strong&gt;&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;  &amp;lt;&lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;chartingToolkit&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;:&lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;Chart &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;x&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;:&lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;Name&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;=&lt;/span&gt;&lt;span style="background: #10100d; color: #44b1e3"&gt;&amp;quot;chEmployeesByDepartment&amp;quot; &lt;br /&gt;       &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;Title&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;=&lt;/span&gt;&lt;span style="background: #10100d; color: #44b1e3"&gt;&amp;quot;# Employees/Department&amp;quot; &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;IsEnabled&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;=&lt;/span&gt;&lt;span style="background: #10100d; color: #44b1e3"&gt;&amp;quot;true&amp;quot; &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;Height&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;=&lt;/span&gt;&lt;span style="background: #10100d; color: #44b1e3"&gt;&amp;quot;300&amp;quot;&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;chartingToolkit&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;:&lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;Chart.Series&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;&amp;gt;
         &amp;lt;&lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;chartingToolkit&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;:&lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;PieSeries    &lt;br /&gt;                &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;x&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;:&lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;Name&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;=&lt;/span&gt;&lt;span style="background: #10100d; color: #44b1e3"&gt;&amp;quot;lnSeries&amp;quot;
                &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;IndependentValuePath &lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;=&lt;/span&gt;&lt;span style="background: #10100d; color: #44b1e3"&gt;&amp;quot;DepartMentName&amp;quot;
                &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;DependentValuePath &lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;=&lt;/span&gt;&lt;span style="background: #10100d; color: #44b1e3"&gt;&amp;quot;Employees.Count&amp;quot;
                &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;SelectionChanged&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;=&lt;/span&gt;&lt;span style="background: #10100d; color: #44b1e3"&gt;&amp;quot;DepartmentSelected&amp;quot;
                &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;IsSelectionEnabled &lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;=&lt;/span&gt;&lt;span style="background: #10100d; color: #44b1e3"&gt;&amp;quot;True&amp;quot; &lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;&amp;gt;
         &amp;lt;/&lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;chartingToolkit&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;:&lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;PieSeries&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;&amp;gt;
      &amp;lt;/&lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;chartingToolkit&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;:&lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;Chart.Series&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;chartingToolkit&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;:&lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;Chart&lt;/span&gt;&lt;span style="background: #10100d; color: #a1b070"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;
  &lt;br /&gt;&lt;/p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;The function to bind the Pie series with the Department information&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: #10100d; color: #d6d694"&gt; private void &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;LoadDepartmentsAndEmployees&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;() {
    &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;DataServiceQuery&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;Department&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;deptQueryWithEmployees &lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;= &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;context&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;.&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;Departments&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;.&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;Expand&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;(&lt;/span&gt;&lt;span style="background: #10100d; color: #44b1e3"&gt;&amp;quot;Employees&amp;quot;&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;) &lt;br /&gt;                                 &lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;as &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;DataServiceQuery&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;Department&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;;
    &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;deptQueryWithEmployees&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;.&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;QueryAndCall&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;(
       (&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;deparmentStatistics&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;) &lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;=&amp;gt;  &lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;{
          &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;Dispatcher&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;.&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;BeginInvoke&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;(
           () &lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;=&amp;gt;  &lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;{ 
                &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;PieSeries &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;series &lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;= &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;chEmployeesByDepartment&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;.&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;Series&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;[&lt;/span&gt;&lt;span style="background: #10100d; color: cyan"&gt;0&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;] &lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;as &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;PieSeries&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;;
                &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;series&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;.&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;ItemsSource &lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;= &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;deparmentStatistics&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;;
               }    
            );       
         }); }&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;Populating employee information when a department is selected in the Pie Series 
    &lt;br /&gt;&lt;/strong&gt;We need to setup the Pie Series in the chart control to allow selection of chart points&amp;#160; and hook into the 

  &lt;br /&gt;SelectionChanged event of the Pie Series. We do this by:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Setting IsSelectionEnabled to true on the Pie Series &lt;/li&gt;

  &lt;li&gt;Hooking up to the SelectionChanged event of the Pie Series &lt;/li&gt;
&lt;/ol&gt;

&lt;pre class="code"&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;        &lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;private void &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;DepartmentSelected&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;(&lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;object &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;sender&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;, &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;SelectionChangedEventArgs &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;e&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;) {  
            &lt;/span&gt;&lt;span style="background: #10100d; color: #ff0080"&gt;//Get the series that caused this  event to be raised
            &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;PieSeries &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;series &lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;= &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;sender &lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;as &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;PieSeries&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;;
            &lt;/span&gt;&lt;span style="background: #10100d; color: #ff0080"&gt;//Get the current selected department in the Series
            &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;Department &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;selectedDepartment &lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;= &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;series&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;.&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;SelectedItem &lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;as &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;Department&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;;
            &lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;if &lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;(&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;selectedDepartment &lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;!= &lt;/span&gt;&lt;span style="background: #10100d; color: #d6d694"&gt;null&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;) { 
                &lt;/span&gt;&lt;span style="background: #10100d; color: #ff0080"&gt;//Set the title of the data grid
                &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;lblSelectedDepartment&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;.&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;Text &lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;= &lt;/span&gt;&lt;span style="background: #10100d; color: #009b00"&gt;String&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;.&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;Format&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;(&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;strSelectedDepartmentMessage&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;, &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;selectedDepartment&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;.&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;DepartMentName&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;);
                &lt;/span&gt;&lt;span style="background: #10100d; color: #ff0080"&gt;//Bind the employee grid with the employees for this department
                &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;dgEmployees&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;.&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;ItemsSource &lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;= &lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;selectedDepartment&lt;/span&gt;&lt;span style="background: #10100d; color: #80ff00"&gt;.&lt;/span&gt;&lt;span style="background: #10100d; color: #e8e8e8"&gt;Employees&lt;/span&gt;&lt;span style="background: #10100d; color: #a79a86"&gt;;
            }  
        }      &lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Download sample project here :&lt;/p&gt;
&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 26px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-925c2d2bb2d03c6b.skydrive.live.com/embedrow.aspx/SLToolkitAstoria/SLToolkitWithAstoria%7C_Chart%7C_DrillDown.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9726027" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/DataServiceContext/default.aspx">DataServiceContext</category></item><item><title>Silverlight toolkit with ADO.NET Data services , Master-Details with Accordion</title><link>http://blogs.msdn.com/phaniraj/archive/2009/06/10/silverlight-toolkit-with-ado-net-data-services-master-details-with-accordion.aspx</link><pubDate>Wed, 10 Jun 2009 10:41:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9723603</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9723603.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9723603</wfw:commentRss><description>&lt;p&gt;Download the sample Silverlight project here : &lt;/p&gt; &lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 26px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-925c2d2bb2d03c6b.skydrive.live.com/embedrow.aspx/SLToolkitAstoria/SLToolkitWithAstoria.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;About the Silverlight toolkit&amp;#160; , &lt;/p&gt;  &lt;p&gt;From their Codeplex page : &lt;a title="http://silverlight.codeplex.com/" href="http://silverlight.codeplex.com/"&gt;http://silverlight.codeplex.com/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;“The Silverlight Toolkit is a collection of Silverlight controls, components and utilities made available outside the normal Silverlight release cycle”&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;In the first of a series I am planning , we will talk about how to achieve a Master-Child display using the Accordion control&amp;#160; &lt;br /&gt;from the Silverlight Toolkit control.&lt;/p&gt;  &lt;p&gt;The data model we will be binding looks like this :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Silverlighttoolk.NETDataservicesTreeView_10E57/SLToolkitAccordion_DataModel.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SLToolkitAccordion_DataModel" border="0" alt="SLToolkitAccordion_DataModel" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Silverlighttoolk.NETDataservicesTreeView_10E57/SLToolkitAccordion_DataModel_thumb.png" width="547" height="191" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Type Employee has a property called Department of type Department.    &lt;br /&gt;Type Department has a collection of type Employee called Employees.&lt;/p&gt;  &lt;p&gt;Employee and Department are related 1..1    &lt;br /&gt;Department and Employee are related 1..M&lt;/p&gt;  &lt;p&gt;We want to bind the Department names to the header of the Accordion and    &lt;br /&gt;the employees as a list inside the content of the accordion.     &lt;br /&gt;When we are done , the final output should look like this :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Silverlighttoolk.NETDataservicesTreeView_10E57/SLTOolkit_Accordionoutput.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SLTOolkit_Accordionoutput" border="0" alt="SLTOolkit_Accordionoutput" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Silverlighttoolk.NETDataservicesTreeView_10E57/SLTOolkit_Accordionoutput_thumb.png" width="464" height="115" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Configuring the header to show the DepartmentName&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The Header template of the Accordion has a textblock which binds to the DepartMentName property of the    &lt;br /&gt;Department entity.     &lt;br /&gt;&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.HeaderTemplate &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
       &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=DepartMentName}&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
       &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
 &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.HeaderTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Configuring the content to show the names of the employees working in the department.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The content of the Accordion pane would be a list box which is bound to the Employees collection of the Department 
  &lt;br /&gt;entity type and shows the EmployeeName as the DisplayMember. 

  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
          &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListBox &lt;/span&gt;&lt;span style="color: red"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Employees&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;DisplayMemberPath&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;EmployeeName&amp;quot;&amp;gt;
          &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;To write the Silverlight client code for this project ,we will need to generate the Client classes with Databinding enabled. 
  &lt;br /&gt;As shown in &lt;a href="http://blogs.msdn.com/astoriateam/archive/2009/03/21/ado-net-data-services-v1-5-ctp1-data-binding-overview.aspx"&gt;this article&lt;/a&gt; on our team blog .&lt;/p&gt;

&lt;p&gt;Once this is done , we have two ways of binding the accordion , 
  &lt;br /&gt;Eager Loading : Download the employees for a department when you download the departments 

  &lt;br /&gt;Lazy Load : Download the employees for a department when the header of an accordion pane , i.e Department is clicked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Eager Loading :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;DataServiceQuery&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Department&lt;/span&gt;&amp;gt; deptQueryWithEmployees = context.Departments.Expand(&lt;span style="color: #a31515"&gt;&amp;quot;Employees&amp;quot;&lt;/span&gt;) &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataServiceQuery&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Department&lt;/span&gt;&amp;gt;;&lt;br /&gt;deptQueryWithEmployees.QueryAndBind(acDepartments);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Since the query part itself isnt interesting in the context of this blog post , I’ve abstracted away the querying into an extension method ( QueryAndBind ) and will be available as part of the download. 
  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Here , as you can see , we are eager loading the Employees for the departments . 
  &lt;br /&gt;I feel that this is wasteful if you have a large number of departments as this not only increases the amount of data on the wire , but it also means that all the data that comes down the wire will be useful .&lt;/p&gt;

&lt;p&gt;For example, if you have about 15 departments and a user may click on 5 or less departments , then downloading employees for all the 15 departments seems inefficient. 
  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Xaml for Eager Loading&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;acDepartments&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;400&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.HeaderTemplate &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=DepartMentName}&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.HeaderTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListBox &lt;/span&gt;&lt;span style="color: red"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Employees&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;DisplayMemberPath&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;EmployeeName&amp;quot;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;Lazy Loading : 
    &lt;br /&gt;&lt;/strong&gt;In this case , we will only bind the Headers and&amp;#160; will bind the Employees only if the header is clicked for that department. In the Silverlight Accordion control , the event SelectionChanged is fired when the header of an Accordion Pane is clicked. 

  &lt;br /&gt;By listening to this event , we can find out which department was clicked and load the Employees for that department using BeginLoadProperty . 

  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;DelayLoad() {
           InitializeComponent();
           context = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TreeViewDataProvider&lt;/span&gt;(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;TreeViewDataService.svc&amp;quot;&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;UriKind&lt;/span&gt;.RelativeOrAbsolute));
           LoadDepartments();
}
&lt;span style="color: blue"&gt;private void &lt;/span&gt;LoadDepartments(){
    ((&lt;span style="color: #2b91af"&gt;DataServiceQuery&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Department&lt;/span&gt;&amp;gt;)context.Departments).QueryAndBind(acDepartments);
}&lt;/pre&gt;
We will subscribe to the SelectionChanged event of the Accordion and add “LoadEmployeesForDepartment” as the event handler. 

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;LoadEmployeesForDepartment(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;SelectionChangedEventArgs &lt;/span&gt;e)
        {
            &lt;span style="color: green"&gt;//The sender is the control that raised the event
            &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Accordion &lt;/span&gt;acControl = sender &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Accordion&lt;/span&gt;;
            &lt;span style="color: green"&gt;//Get the Selected Department
            &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Department &lt;/span&gt;selectedDepartment = acControl.SelectedItem &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Department&lt;/span&gt;;
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(
                &lt;span style="color: green"&gt;//If the Selected object is department
                &lt;/span&gt;selectedDepartment != &lt;span style="color: blue"&gt;null 
                &lt;/span&gt;&amp;amp;&amp;amp; (
                &lt;span style="color: green"&gt;// If the Employees collection is null or empty
                &lt;/span&gt;selectedDepartment.Employees == &lt;span style="color: blue"&gt;null &lt;/span&gt;|| selectedDepartment.Employees.Count == 0)
                )
            {
                &lt;span style="color: green"&gt;//Call load property , which updates the Employees collection of this instance 
                //and the UI automatically updates itself, since Department type implements INotifyPropertyChanged
                &lt;/span&gt;context.LoadPropertyAndCall&amp;lt;&lt;span style="color: #2b91af"&gt;Employee&lt;/span&gt;&amp;gt;(selectedDepartment, &lt;span style="color: #a31515"&gt;&amp;quot;Employees&amp;quot;&lt;/span&gt;,
                    &lt;span style="color: blue"&gt;null&lt;/span&gt;);
            }

        }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;XAML for Delay Load :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;acDepartments&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;SelectionChanged&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;LoadEmployeesForDepartment&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.HeaderTemplate &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=DepartMentName}&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.HeaderTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListBox &lt;/span&gt;&lt;span style="color: red"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Employees&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;DisplayMemberPath&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;EmployeeName&amp;quot;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Download the sample Silverlight project here : &lt;/p&gt;
&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 26px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-925c2d2bb2d03c6b.skydrive.live.com/embedrow.aspx/SLToolkitAstoria/SLToolkitWithAstoria.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;&lt;strong&gt;Running the sample app &lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Set SLToolkitWithAstoriaWeb as the Start-up project. &lt;/li&gt;

  &lt;li&gt;Set SLToolkitWithAstoriaTestPage.html as the start-up page. &lt;/li&gt;

  &lt;li&gt;To run the EagerLoading sample , just hit F5 &lt;/li&gt;

  &lt;li&gt;To run the DelayLoad sample , follow a-c and add the Query string ?delayLoad to the address bar in the browser that comes up. &lt;/li&gt;
&lt;/ol&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9723603" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/DataServiceContext/default.aspx">DataServiceContext</category></item><item><title>ADO.NET Data Services Silverlight Project Error : System.IO.FileNotFoundException</title><link>http://blogs.msdn.com/phaniraj/archive/2009/03/24/ado-net-data-services-silverlight-project-error-system-io-filenotfoundexception.aspx</link><pubDate>Tue, 24 Mar 2009 05:09:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9503162</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9503162.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9503162</wfw:commentRss><description>&lt;p&gt;Imagine this , you just downloaded the Astoria V1.5 CTP1 and are happily chugging along and decide to make a Silverlight Project    &lt;br /&gt;that uses the latest Silverlight client library to make some cool app.     &lt;br /&gt;You open an existing Silverlight app&amp;#160; /create a new Silverlight app ,     &lt;br /&gt;and generate the client types by running “Add Service Reference” from Visual Studio.     &lt;br /&gt;and write some code in the app and hit F5 to run the app .     &lt;br /&gt;Now , Instead of seeing the poetic beauty that is a Silverlight app built with Astoria , you see this : &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/cf33f5160cc9_FD05/M_D_S_C_Unhandled_Exception.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="M_D_S_C_Unhandled_Exception" border="0" alt="M_D_S_C_Unhandled_Exception" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/cf33f5160cc9_FD05/M_D_S_C_Unhandled_Exception_thumb.png" width="439" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The Exception message is : &lt;/p&gt;  &lt;p&gt;System.IO.FileNotFoundException occurred    &lt;br /&gt;&amp;#160; Message=&amp;quot;Could not load file or assembly 'Microsoft.Data.Services.Client, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; The system cannot find the file specified.&amp;quot;     &lt;br /&gt;&amp;#160; StackTrace:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; at SilverlightProject1.Page..ctor()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; at SilverlightProject1.App.Application_Startup(Object sender, StartupEventArgs e)     &lt;br /&gt;&amp;#160; InnerException: &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;strong&gt;What just happened ?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;When the tools which generate the client code for an Astoria Service for Silverlight applications ran , they added a reference to the new client dll,    &lt;br /&gt;Microsoft.Data.Services.Client.dll with “Copy Local” set to false.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/cf33f5160cc9_FD05/M_D_S_C_Silverlight_Reference_1.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="M_D_S_C_Silverlight_Reference" border="0" alt="M_D_S_C_Silverlight_Reference" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/cf33f5160cc9_FD05/M_D_S_C_Silverlight_Reference_thumb_1.png" width="276" height="484" /&gt;&lt;/a&gt; &lt;/p&gt; If your code looks like this,   &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;Page(){
InitializeComponent();
nwServiceReference.&lt;span style="color: #2b91af"&gt;BlogServiceProvider &lt;/span&gt;prov =
                &lt;span style="color: blue"&gt;new &lt;/span&gt;SilverlightProject1.nwServiceReference.&lt;span style="color: #2b91af"&gt;BlogServiceProvider&lt;/span&gt;(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;http://ServiceEndPoint&amp;quot;&lt;/span&gt;));
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;When the JIT compiler compiles your Page() constructor method, it scans the method, sees that it references a type named &lt;span style="color: #2b91af"&gt;BlogServiceProvider &lt;/span&gt;, and attempts to load Microsoft.Data.Services.Client.dll so that the reference can be resolved. 

  &lt;br /&gt;Now , Since we set Copy Local to false , the Client DLL is not copied into the XAP file ,and the Silverlight CLR cannot find the file , it throws the above exception. 

  &lt;br /&gt;We can verify by opening the xap file in winrar or some other archiving utility. 

  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/cf33f5160cc9_FD05/Xap_No_CLient_Library.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Xap_No_CLient_Library" border="0" alt="Xap_No_CLient_Library" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/cf33f5160cc9_FD05/Xap_No_CLient_Library_thumb.png" width="644" height="327" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resolution :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your Silverlight project, for the reference to “'Microsoft.Data.Services.Client.dll” ,&amp;#160; Set “Copy Local” to “True” and rebuild your Silverlight XAP. 
  &lt;br /&gt;

  &lt;br /&gt;&lt;strong&gt;What about “Update Service Reference”? 
    &lt;br /&gt;&lt;/strong&gt;Same issue , follow same resolution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When will this be fixed? 
    &lt;br /&gt;&lt;/strong&gt;We are tracking this issue and will release a fix in a future release of ADO.NET Data Services v1.5 &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9503162" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Interim Release: Making SL2 Beta 2 Clients Work With .NET Fx 3.5 SP1 RTM Servers</title><link>http://blogs.msdn.com/phaniraj/archive/2008/09/03/interim-release-making-sl2-beta-2-clients-work-with-net-fx-3-5-sp1-rtm-servers.aspx</link><pubDate>Wed, 03 Sep 2008 02:27:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8920950</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/8920950.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=8920950</wfw:commentRss><description>&lt;p&gt;Cross-posted from here : &lt;a href="http://blogs.msdn.com/astoriateam/archive/2008/09/02/interim-release-making-sl2-beta-2-clients-work-with-net-fx-3-5-sp1-rtm-servers.aspx"&gt;Interim Release: Making SL2 Beta 2 Clients Work With .NET Fx 3.5 SP1 RTM Servers&lt;/a&gt;    &lt;br /&gt;    &lt;br /&gt;As an offshoot of the feedback we got from different channels , ( Blogs , Direct emails to team members , our discussion forums, etc) we are releasing an “interim build” of the data services&amp;#160; Silverlight client which works with the&amp;#160; Silverlight 2 Beta 2 runtime ,and works with the RTM ADO.NET Data Services Server released as part of .Net Framework 3.5 SP1 RTM. &lt;/p&gt;  &lt;p&gt;Download Location : &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=CF8F88C3-D869-46DE-A7BF-FB7712C791B7&amp;amp;displaylang=en"&gt;ADO.NET Data Services Silverlight 2 B2 Client Refresh&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;How did we get here ? &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;We have different ship vehicles for the client and the server components. &lt;/p&gt;  &lt;p&gt;When the Silverlight 2 Beta 2 Client shipped , the ADO.NET Data Services&amp;#160; Server which was available was the one from .NET Framework 3.5 SP1 Beta1 and we made the SL client library work with the Server which was available when SL2 Beta 2 shipped. &lt;/p&gt;  &lt;p&gt;When the RTM of .NET Framework 3.5 SP1 was released, the Silverlight Client library was still the one from the SL2 Beta 2 release. &lt;/p&gt;  &lt;p&gt;The original plan was to ship a Silverlight Client Library for ADO.NET Data Services when Silverlight 2 RTMs.&amp;#160; This meant that for a certain period of time , between when 3.5 SP1 RTM and SL2.0 RTM,&amp;#160; users would have a Silverlight Client Library for ADO.NET Data Services which would not work with the RTM Server. &lt;/p&gt;  &lt;p&gt;You can read more about this here :&amp;#160; &lt;a href="http://blogs.msdn.com/ADO.NET%20Data%20Servicesteam/archive/2008/08/12/compat-note-silverlight-beta-2-client-net-framework-3-5-sp1-server-components.aspx"&gt;Compat Note: Silverlight Beta 2 Client &amp;amp; .NET Framework 3.5 SP1 Server Components&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;What is this release about ? &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;We took the Silverlight Client Library code that was going be released as part of the SL 2.0 RTM SDK (or almost, you never know when you’re set and won’t touch the bits again) and built it against the SL 2 Beta 2 Runtime and SDK components.This new downloadable assembly will allow your Silverlight applications built against Silverlight 2 Beta 2 to talk to Data Services servers built with the .NET 3.5 SP1 RTM release &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Should everyone upgrade to this release of the client library ?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;If your client applications are built on SL2 Beta 2 SDK and talk&amp;#160; to the ADO.NET Data Services Server released as part of &lt;b&gt;.NET Framework 3.5 SP1 Beta1&lt;/b&gt; , then upgrading to this Assembly will &lt;b&gt;break your client applications.&amp;#160; &lt;/b&gt;&lt;b&gt;Don’t upgrade unless the Data Services Server is from .NET Framework 3.5 SP1 RTM.&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;If you want your Silverlight applications built on SL2 Beta 2 SDK to talk to the Astoria Server released as part of the &lt;b&gt;.NET Framework 3.5 SP1 RTM&lt;/b&gt;, then you should upgrade to this version of the System.Data.Services.Client Library. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Are there any gotchas to be aware of ? &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Yes -- &lt;strong&gt;Don’t depend on this “interim release” for your production applications.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Wait until Silverlight 2.0 RTMs to deploy any Silverlight applications that use the System.Data.Services.Client library. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;How different is this from the RTM library ? &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Well, most of the code is the same as will be shipped in the Silverlight RTM SDK.&amp;#160; The difference being that we have to depend on the SL2 Beta 2 Runtime for certain core functionality.&amp;#160; So , consider this an early look at something close to what will come later on.&amp;#160; Any feedback you give us will only help make the RTM library that much better. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Using the new Assembly&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Download the new Silverlight Client Assembly from here : &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=CF8F88C3-D869-46DE-A7BF-FB7712C791B7&amp;amp;displaylang=en"&gt;ADO.NET Data Services Silverlight 2 B2 Client Refresh&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Installing the New Silverlight Client Assembly&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;1.&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Go to the %ProgramFiles%\Microsoft SDKs\Silverlight\v2.0\Libraries\Client folder &lt;/p&gt;  &lt;p&gt;2.&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Backup the older System.Data.Services.Client.dll &lt;/p&gt;  &lt;p&gt;3.&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Replace the older assembly with the new one. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Upgrading your applications to use the new SL Client Assembly&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;1.&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Remove any references to the older SL client library in your applications . &lt;/p&gt;  &lt;p&gt;2.&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Compile to make sure that the build fails . &lt;/p&gt;  &lt;p&gt;3.&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Add a reference to the newer SL Client assembly . &lt;/p&gt;  &lt;p&gt;4.&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Compile again to make sure that the build succeeds . &lt;/p&gt;  &lt;p&gt;Phani Raj    &lt;br /&gt;ADO.NET Data Services Test Team&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8920950" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Silverlight/default.aspx">Silverlight</category></item></channel></rss>