SYS-CON Media
 Early-Bird Savings!
 
AJAXWorld Diamond Sponsor
AJAXWorld Platinum Sponsors
AJAXWorld Gold Sponsors
AJAXWorld Silver Sponsors
AJAXWorld Exhibitors
AJAXWorld Media Sponsors
Goingtomeet.com Conference Directory
 
Association Sponsor
2006 Sponsors
 
Can't Miss RSS Feed
Subscribe to the AJAXWorld.com RSS Feed & Get All The Conference News As It Happens!

3 Rockin' Days of AJAX: March 19-21, 2007 New York City


Accessing the ASP.NET Authentication, Profile and Role Service in Silverlight
How to access the WCF application services from a directly from the Silverlight client

Part 2: Save Personalization Settings

In this part I will show how to leverage the ASP.NET profile system to store and retrieve data tied to a particular user.  The beautiful thing about this is there is no explicit database configuration required.

First, let's go back to the ASP.NET server project and add the ProfileService.svc.  The easiest way to do this might be to copy the AuthenticationService.svc change the file name and then change the contents as show below.

<%@ ServiceHost Language="C#" Service=
"System.Web.ApplicationServices.
ProfileService"
%>

Now, we need to enable the service via WCF configuration in web.config.  This looks just like the config for the prfofile service.  In the system.serviceModel\services section add a new node.

      <!-- this enables the WCF 
ProfileService endpoint
--> <service name=
"System.Web.ApplicationServices.
ProfileService
" behaviorConfiguration=
"ProfileServiceTypeBehaviors"> <endpoint contract=
"System.Web.ApplicationServices.
ProfileService
" binding="basicHttpBinding"
bindingConfiguration
="userHttp" bindingNamespace=
"http://asp.net/
ApplicationServices/v200
"/> </service>

and in the system.serviceModel\behaviors\serviceBehaviors add a new node

        <behavior name=
"ProfileServiceTypeBehaviors"> <serviceMetadata
httpGetEnabled
="true"/> </behavior>



Now we need to configure the profile system.  Again, in web.config add a section listing all the profile properties.  In the System.web section, add the following node.

    <profile>
      <properties>
        <add name="Color" type=
"string" defaultValue="Red" /> </properties> </profile>

 

Now we need to enable profile service to be accessed from the webservice. To do this, add the following node to the system.web.extensions\scripting\webservices section.

        <profileService enabled=
"true" readAccessProperties=
"Color" writeAccessProperties=
"Color"/>

Now, let's go to the Silverlight client and add a reference to this service.  This is the same as we did authentication service. Add Service Reference, Discover and select the profileService.

image

 

Now, we need to add a little UI to the page.xaml in order to give us a way to view and edit the personalized setting.

            <StackPanel Orientation=
"Horizontal"
HorizontalAlignment=
"Center"> <
TextBlock>Favorite Color:
</TextBlock> <TextBox x:Name=
"colorNameBox"

Width
="100" Height=
"25"></
TextBox> <Button x:Name=
"submitButton"

Width
="50" Height="25" Content="submit" Click=
"submitButton_Click"
>
</
Button> </StackPanel>

Now, let's extend loginComplete to retrieve all the profile properties for the user that just logged in.   Again, we need to do that asynchronously so we don't block the browser.

void client_LoginCompleted
(object sender,
LoginCompletedEventArgs
e) { if (e.Error != null) statusText.Text =
e.Error.ToString(); else { statusText.Text = e.UserState +
" logged In result:" + e.Result; ProfileServiceClient client =
new
ProfileServiceClient(); client.GetAllProperties
ForCurrentUserAsync(false); client.GetAllProperties
ForCurrentUserCompleted +=
new
EventHandler
<GetAllPropertiesFor
CurrentUserCompletedEventArgs
>
(client_GetAllProperties
ForCurrentUserCompleted); } }

When we get the property values back, we just set the LayoutRoot to have that background.

void client_GetAllProperties
ForCurrentUserCompleted
(object sender,
GetAllPropertiesForCurrent
UserCompletedEventArgs
e) { if (e.Error == null) { colorNameBox.Text =
e.Result["Color"]; ChangeBackgroundColor
(e.Result["Color"]); } }
private void ChangeBackgroundColor
(string colorName) { SolidColorBrush brush =
new
SolidColorBrush(); switch (colorName.ToLower()) { case "black": brush.Color = Colors.Black; break; case "blue": brush.Color = Colors.Blue; break; case "brown": brush.Color = Colors.Brown; break; case "green": brush.Color = Colors.Green; break; case "orange": brush.Color = Colors.Orange; break; case "purple": brush.Color = Colors.Purple; break; case "yellow": brush.Color = Colors.Yellow; break; case "red": brush.Color = Colors.Red; break; case "white": default: brush.Color = Colors.White; break; } LayoutRoot.Background = brush; }

Finally, when the submit button is pressed we need to set the value on the server.. for completeness, I show waiting until the result comes back from the server before setting the background locally.

private void submitButton_Click
(object sender, RoutedEventArgs e) { ProfileServiceClient client =
new
ProfileServiceClient(); Dictionary<string, object> properites =
new
Dictionary<string,object>(); properites.Add("Color",colorNameBox.Text); client.SetPropertiesForCurrentUserAsync
(properites, false, properites); client.SetProperties
ForCurrentUserCompleted +=
new EventHandler
<SetPropertiesForCurrent
UserCompletedEventArgs
>
(client_SetPropertiesFor
CurrentUserCompleted); } void client_SetPropertiesFor
CurrentUserCompleted
(object sender,
SetPropertiesForCurrentUser
CompletedEventArgs
e) { Dictionary<string, object>
properites = e.UserState as
Dictionary<string, object>; ChangeBackgroundColor
((string)properites["Color"]); }

The end result looks good!  Notice the employee and the manager can each have different values for color.

image

 

image

 

 

Next Page - Part 3. Enable Custom UI Based on a User's Role

About Brad Abrams
Brad Abrams is currently the Group Program Manager for the UI Framework and Services team at Microsoft which is responsible for delivering the developer platform that spans both client and web based applications, as well as the common services that are available to all applications. Specific technologies owned by this team include ASP.NET, Atlas and Windows Forms. He was a founding member of both the Common Language Runtime, and .NET Framework teams.

Brad has been designing parts of the .NET Framework since 1998 when he started his framework design career building the BCL (Base Class Library) that ships as a core part of the .NET Framework. He was also the lead editor on the Common Language Specification (CLS), the .NET Framework Design Guidelines, the libraries in the ECMA\ISO CLI Standard, and has been deeply involved with the WinFX and Windows Vista efforts from their beginning.

He co-authored Programming in the .NET Environment, and was editor on .NET Framework Standard Library Annotated Reference Vol 1 and Vol 2 and the Framework Design Guidelines.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Hey Brad,

Great Post.....

Thanks...

This is great! Been looking forward to seeing more AJAX with Silverlight and this is right up my alley. Now that I know how it works... do you think there's a version out there with advanced escaping or is this security sound across the board?
**************
Nico del Castillo
Microsoft Security Outreach Team
www.microsoft.com/hellosecureworld7


Latest AJAXWorld RIA Stories
DX World EXPO, LLC, a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the ...
Companies are harnessing data in ways we once associated with science fiction. Analysts have access to a plethora of visualization and reporting tools, but considering the vast amount of data businesses collect and limitations of CPUs, end users are forced to design their structu...
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct ...
In his session at 21st Cloud Expo, James Henry, Co-CEO/CTO of Calgary Scientific Inc., introduced you to the challenges, solutions and benefits of training AI systems to solve visual problems with an emphasis on improving AIs with continuous training in the field. He explored app...
The question before companies today is not whether to become intelligent, it’s a question of how and how fast. The key is to adopt and deploy an intelligent application strategy while simultaneously preparing to scale that intelligence. In her session at 21st Cloud Expo, Sangeeta...
Untitled Document

Call 201 802-3020 or Click Here to Save $100!

Save $100

Sponsorship Opportunities
AJAXWorld offers the undisputed best platform to position your company as a leading vendor in the fast-emerging marketplace for AJAX and Web 2.0.


Please call
(201)802-3020

Don't Miss the Laszlo Track
On March 20, 2007 New York City's Roosevelt Hotel will host SYS-CON Events' first "Laszlo Track" about Next-Generation Web Application Development!
Learn Laszlo in sessions including: Inside the U.S. Air Force: How AJAX Is Improving Communications and Quality of Life, Creating the Cinematic User Experience, Real-World AJAX Success Stories, Introducing Laszlo Webtop, OpenLaszlo and AJAX and Hands-On Open Laszlo training!

Brought To You By:

AJAXWorld Magazine is the pre-eminent independent vendor-neutral resource for the fastest growing new segment of the software business: entirely Web-based applications and experiences.
Download the Premier Issue!
Download the Premier 2007 Issue!
Web 2.0 Journal is the world's only completely Web 2.0-focused resource, read and written by some of the world's top analysts, IT executives, rich-media developers, A-bloggers and activists.

AJAXWorld Webcasts



AJAXWorld Sessions on SYS-CON.TV

· Bill Scott - Yahoo! UI Library
· David Heinemeier Hansson - AJAX on Rails
· Jesse James Garrett - Elements of User Experience
· Dion Hinchcliffe - Real World AJAX
· Eric Miraglia - Open Source AJAX Development
· Paul Rademacher - Mashing Up Your Web Application
· Adam Sah - Google Gadgets
· Doug Crockford - An Introduction to JavaScript
· David Linthicum - Enterprise Web 2.0
· Patrick Grady - The Imagination & Experience Web

AJAXWorld...All The AJAX Rock Stars in One Spot!


2007 Conference Speakers Include


TEMKIN
Laszlo Systems

COENRAETS
Adobe

WOLF
Cynergy

CRUPI
JackBe

SAH
Google

ANDREWS
Evans Data

CROCKFORD
Yahoo!

WEI
Nexaweb

MURRY
Sun

ABRAMS
Microsoft

HINCHCLIFF
AWM

HOFFMAN
SPI Dynamics

HAKMAN
TIBCO

BOYD
Blue Whale Labs

KING
Hibernate

CHARLAND
Nitobi

AJAXWorld University Developer Bootcamp

On March 19, 2007 - New York City, AJAXWorld University's "AJAX Developer Bootcamp" will be an intensive, one-day hands-on training program that will teach Web developers and designers how to build high-quality AJAX applications from beginning to end. Held the day before the AJAXWorld Conference & Expo begins, the Bootcamp is intended to be the premier AJAX instructional program presently available anywhere.
view the full one-day schedule

Flex Bootcamp

March 18, 2007 the "Adobe Flex  Developer Bootcamp" is an intensive, one-day hands-on training program that will teach Web developers and designers how to build Rich Internet Application using Adobe Flex. During this day attendees will  create two fully functional applications.  Pre-requisites: working knowledge of any object-oriented programming language. This workshop will be  taught by Flex experts from Farata Systems – Yakov Fain and Dr. Victor Rasputnis, co-authors of the book Developing RIA with Adobe Flex and Java.  If you want to jump-start your new Flex project, this workshop is as good as it gets.
view the full one-day schedule


Past Events Archive

Real-World AJAX Seminar
www.ajaxseminar.com
Ruby on Rails Seminar
www.rubyonrailsseminar.com
Real-World Flex Seminar
www.flexseminar.com
Other SYS-CON Events
events.sys-con.com
Who Should Attend?
  • Web Programmers and Designers
  • Technology Evangelists
  • Senior Architects
  • Project Managers
  • User Interface Architects
  • Web Consultants
  • C-Level Execs and Developers Who Need to Stay in Front of the Latest Web Technology!

Video Coverage of the AJAXWorld 2006 Panels

SYS-CON TV Power Panel: Web-Oriented Architecture: SOA + The Web + REST
SYS-CON TV Power Panel: Redefining RIAs: Does AJAX Push the Browser Too Far
SYS-CON TV Power Panel: AJAXWorld 2006 CEO Power Panel
SYS-CON TV Power Panel: The FrameworkWars: Lightweight vs Heavyweight

Join Over 3,600 Early AJAX Adopters
Who Have Attended AJAXWorld
• A&R Edelman
• Academic Enterprise
• Accoona Corp [2 delegates]
• Acxiom
• Adams Capital Management
• Adaptive Edge
• Adaptive Path
• Adobe Systems Incorporated [21 delegates]
• Adobe Systems Romania
• Ajax13
• All Risks, Ltd.
• alliance
• Alliance For Community Care
• AlphaDetail Inc
• Altera Corporation
• Amazon.com [6 delegates]
• Appeon Corporation [2 delegates]
• Apple Computer [5 delegates]
• Apress [3 delegates]
• Arkivio
• ASA
• Astute Solutions
• Avaya Inc [2 delegates]
• Avenda Systems
• Avenue A | Razorfish [3 delegates]
• Axcella, LLC [2 delegates]
• Aximsoft
• Azimyth
• Backbase USA Inc. [4 delegates]
• BAE Systems [2 delegates]
• Bank of America [2 delegates]
• Barkley Evergreen & Partners Interactive
• Bayview Financial [2 delegates]
• BEA Systems [3 delegates]
• Billeo
• BMC Software, Inc. [2 delegates]
• Borland Software Corporation
• Bradford Technologies, Inc [2 delegates]
• Brilliance
• Brocade Communications Systems, Inc. [2 delegates]
• Brookside Capital LLC
• Brulant
• Bungee Labs, Inc [6 delegates]
• Bureau of Labor Statistics
• BUZ Interactive
• Cadena Software
• Calix Networks
• Callidus Software [2 delegates]
• Cambia Security
• Carnegie Mellon West
• Cautella, Inc.
• CBSA
• Celequest [3 delegates]
• Change Vision, Inc.
• Charles E. Kenney, CPA
• Charles Schwab & Co., Inc. [8 delegates]

   read more...


ADVERTISE   |   MAGAZINE SUBSCRIPTIONS   |   FREE BREAKING-NEWSLETTERS!   |   SYS-CON.TV   |   BLOG-N-PLAY!   |   WEBCAST   |   EDUCATION   |   RESEARCH

.NET Developer's Journal - .NETDJ   |   ColdFusion Developer's Journal - CFDJ   |   Eclipse Developer's Journal - EDJ   |   Enterprise Open Source Magazine - EOS
Open Web Developer's Journal - OPEN WEB   |   iPhone Developer's Journal - iPHONE   |   Virtualization - Virtualization   |   Java Developer's Journal - JDJ   |   Linux.SYS-CON.com
PowerBuilder Developer's Journal - PBDJ   |   SEO / SEM Journal - SJ   |   SOAWorld Magazine - SOAWM   |   IT Solutions Guide - ITSG   |   Symbian Developer's Journal - SDJ
WebLogic Developer's Journal - WLDJ   |   WebSphere Journal - WJ   |   Wireless Business & Technology - WBT   |   XML-Journal - XMLJ   |   Internet Video - iTV
Flex Developer's Journal - Flex   |   AJAXWorld Magazine - AWM   |   Silverlight Developer's Journal - SLDJ   |   PHP.SYS-CON.com   |   Web 2.0 Journal - WEB2

SYS-CON MEDIA:   ABOUT US   |   CONTACT US   |   COMPANY NEWS   |   CAREERS   |   SITE MAP
SYS-CON EVENTS  |  AJAXWorld Conference & Expo  |  iPhone Developer Summit  |  OpenWeb Developer Summit  |  SOA World Conference & Expo  |  Virtualization Conference & Expo
INTERNATIONAL SITES:   India  |  U.K.  |  Canada  |  Germany  |  France  |  Australia  |  Italy  |  Spain  |  Netherlands  |  Brazil  |  Belgium
 Terms of Use & Our Privacy Statement     About Newsfeeds / Video Feeds
Copyright ©1994-2008 SYS-CON Publications, Inc. All Rights Reserved. All marks are trademarks of SYS-CON Media.
Reproduction in whole or in part in any form or medium without express written permission of SYS-CON Publications, Inc. is prohibited.