Archive for ◊ February, 2011 ◊

Saturday, February 19th, 2011
Distributed development is a fact of life for many teams. Unfortunately most agile methodologies or approaches assume that the team is located in a single team room. Until recently there has been little guidance about how to apply these approaches with a geographically dispersed team.
Microsoft’s patterns & practices group has been following an agile, distributed development approach for the past five years. During this time teams within the group have experimented extensively with different approaches to best address the challenges of distributed agile development. Ade Miller from Microsoft Patterns & Practices has written a paper that outlines the challenges faced by geographically distributed agile teams and details some proven practices to address these issues and build successful distributed teams.
Download the pdf here.

Distributed development is a fact of life for many teams. Unfortunately most agile methodologies or approaches assume that the team is located in a single team room. Until recently there has been little guidance about how to apply these approaches with a geographically dispersed team.

Microsoft’s patterns & practices group has been following an agile, distributed development approach for the past five years. During this time teams within the group have experimented extensively with different approaches to best address the challenges of distributed agile development. Ade Miller from Microsoft Patterns & Practices has written a paper that outlines the challenges faced by geographically distributed agile teams and details some proven practices to address these issues and build successful distributed teams.

Download the pdf here.

Thursday, February 17th, 2011

WCF handles errors and convey these details to the client using Fault contracts. SOAP fault messages are included in the metadata for an operation contract and when the exception is raised in these methods create a fault for the clients to get more details about the exceptions. But when you have a client that runs on 2.0 version of .NET framework, they can’t make use of these fault contracts. In this case you need to send your faults as SOAP exceptions as in Web services.

For e.g.

public void MyServiceMethod()

{

try

{

//Application Logic

}

catch (System.Security.SecurityException securityException)

{

throw GenerateSoapException(“ServiceMethodName”, “YourNamespace”, securityException.Message, “1000″, securityException.Source, ServiceFaultLocation.FromServerCode);

}

}

private SoapException GenerateSoapException(string uri,

string serviceNamespace,

string message,

string errNum,

string source,

ServiceFaultLocation faultLocation)

{

XmlQualifiedName faultCodeLocation = SetFaultCode(faultLocation);

XmlDocument xmlDoc = new XmlDocument();

XmlNode rootNode = CreateExceptionNode(serviceNamespace, message, errNum, source, xmlDoc);

SoapException soapException = new SoapException(message, faultCodeLocation, uri, rootNode);

return soapException;

}

private XmlNode CreateExceptionNode(string serviceNamespace, string message, string errNum, string source, XmlDocument xmlDoc)

{

XmlNode rootNode = xmlDoc.CreateNode(XmlNodeType.Element, SoapException.DetailElementName.Name, SoapException.DetailElementName.Namespace);

XmlNode errorNode = PopulateErrorDetails(serviceNamespace, message, errNum, source, xmlDoc);

rootNode.AppendChild(errorNode);

return rootNode;

}

private XmlNode PopulateErrorDetails(string serviceNamespace, string message, string errNum, string source, XmlDocument xmlDoc)

{

XmlNode errorNode = xmlDoc.CreateNode(XmlNodeType.Element, “Error”, serviceNamespace);

XmlNode errorNumberNode = xmlDoc.CreateNode(XmlNodeType.Element, “ErrorNumber”, serviceNamespace);

errorNumberNode.InnerText = errNum;

XmlNode errorMessageNode = xmlDoc.CreateNode(XmlNodeType.Element, “ErrorMessage”, serviceNamespace);

errorMessageNode.InnerText = message;

XmlNode errorSourceNode = xmlDoc.CreateNode(XmlNodeType.Element, “ErrorSource”, serviceNamespace);

errorSourceNode.InnerText = source;

errorNode.AppendChild(errorNumberNode);

errorNode.AppendChild(errorMessageNode);

errorNode.AppendChild(errorSourceNode);

return errorNode;

}

private XmlQualifiedName SetFaultCode(ServiceFaultLocation code)

{

XmlQualifiedName faultCodeLocation = null;

switch (code)

{

case ServiceFaultLocation.FromClientCode:

faultCodeLocation = SoapException.ClientFaultCode;

break;

case ServiceFaultLocation.FromServerCode:

faultCodeLocation = SoapException.ServerFaultCode;

break;

}

return faultCodeLocation;

}

Later in your client you can use this SOAP exception and parse the XML message to get the details of the exception.

Category: .Net | Tags: ,  | 2 Comments
Wednesday, February 16th, 2011

Regions in Prism have been extended to support a more general notion of navigation, based on URIs and an extensible navigation mechanism.

Navigation within a region means that a new view is to be displayed within that region. The view to be displayed is identified via a URI, which, by default, refers to the name of the view to be created. You can programmatically initiate navigation using the RequestNavigate method defined by the INavigateAsync interface.

RegionManager in prism have a RequestNavigate method which allows you to specify the name of the region to be navigated. This convenient method obtains a reference to the specified region and then calls the RequestNavigate method, as shown in the code.

private void OnViewNavigationRequested()

{

_regionManager.RequestNavigate(“MainRegion”

, new Uri(“EmployeeView1″, UriKind.Relative)

, (navigationResult) =>

{

if (navigationResult.Result == true) MessageBox.Show(“Success”);

else MessageBox.Show(“Failed”);

});

}

The views need to be registered with the region for navigation to work.

[Import]

public EmployeeView1 View1 { get; set; }

[Import]

public EmployeeView2 View2 { get; set; }

public void Initialize()

{

CreateNavigationTabAndRegisterModule();

RegisterViewsWithRegion();

}

private void RegisterViewsWithRegion()

{

_regionManager.RegisterViewWithRegion(“MainRegion”, () => View1);

_regionManager.RegisterViewWithRegion(“MainRegion”, () => View2);

}

View and View Model Participation in Navigation

The INavigationAware interface is implemented by the View and ViewModel to participate in the navigation process. The interface defines the methods

public interface INavigationAware

{

bool IsNavigationTarget(NavigationContext navigationContext);

void OnNavigatedFrom(NavigationContext navigationContext);

void OnNavigatedTo(NavigationContext navigationContext);

}

The OnNavigatedFrom method can be implemented to save the state of the currently active view or viewmodel before navigation. Similarly OnNavigatedTo method can be used to find details of the view or viewmodel navigated to.

If you want to confirm the navigation from the view, the IConfirmNavigationRequest interface can be implemented on the View or ViewModel to confirm the navigation request. The navigation can be canceled or confirmed based on the logic implemented in the ConfirmNavigationRequest method.

public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)

{

if (MessageBox.Show(“Confirm navigation from this view?”, “Confirm navigation”, MessageBoxButton.OKCancel) == MessageBoxResult.OK)

continuationCallback(true);

else

continuationCallback(false);

}

Category: .Net, Silverlight | Tags: , ,  | One Comment
Author:
Monday, February 14th, 2011
Software Testing is a process of verifying and validating whether the software developed is working as expected. It is a process of analyzing software to find the bugs.
Testing is the most important phase in software development. If you don’t test your source code then your are not verifying that your software worked as expected.
There are various types of software testing strategies such as white box testing strategy, black box testing strategy etc. In this article I am going to explain the most important white box testing strategy called “UNIT TESTING”. PHP will be the programming language used.
Unit Testing means testing of individual components and module. This is typically done by a developer because it requires knowledge of program design and code.
Few developers or software owners have misconception about unit testing that it is time consuming and unnecessary waste of time. Even I felt the same way initially, but later I figured out that it’s worth unit testing your code because it reduces your time in future, modifying and maintaining undetected code or bug. Imagine a complex project which has many modules. Now if you have unit tested all these modules then introducing a new module into the system will be easier because the integration issues can be detected immediately. But if you have not unit tested your code then it is harder to introduce a new module because it might have the impact on the other parts of the system. But this doesn’t mean that you can’t test the legacy code. I will be writing on how to handle the legacy code in my future article.
Unit testing is definitely is one of the means of making developers life easier.
There are many frameworks available for unit testing your code using PHP. Once such framework in PHP is “PHPUNIT”.
PHPUNIT is derived from the popular java unit testing framework called JUnit.
I have researched on PHPUNIT and I feel that there is not enough documentation on installing and using it. It is time consuming for a developer initially because of the lack of documentation. This is my personal experience.

Software Testing is a process of verifying and validating whether the software developed is working as expected. It is a process of analyzing software to find the bugs.

Testing is the most important phase in software development. If you don’t test your source code then your are not verifying that your software worked as expected.

There are various types of software testing strategies such as white box testing strategy, black box testing strategy etc. In this article I am going to explain the most important white box testing strategy called “UNIT TESTING”. PHP will be the programming language used.

Unit Testing means testing of individual components and module. This is typically done by a developer because it requires knowledge of program design and code.

Few developers or software owners have misconception about unit testing that it is time consuming and unnecessary waste of time. Even I felt the same way initially, but later I figured out that it’s worth unit testing your code because it reduces your time in future, modifying and maintaining undetected code or bug. Imagine a complex project which has many modules. Now if you have unit tested all these modules then introducing a new module into the system will be easier because the integration issues can be detected immediately. But if you have not unit tested your code then it is harder to introduce a new module because it might have the impact on the other parts of the system. But this doesn’t mean that you can’t test the legacy code. I will be writing on how to handle the legacy code in my future article.

Unit testing is definitely is one of the means of making developers life easier.

There are many frameworks available for unit testing your code using PHP. Once such framework in PHP is “PHPUNIT”.

PHPUNIT is derived from the popular java unit testing framework called JUnit.

I have researched on PHPUNIT and I feel that there is not enough documentation on installing and using it. It is time consuming for a developer initially because of the lack of documentation. This is my personal experience.Hopefully this article will help you get started with PHPUnit.

The best and easiest way to install PHPUNIT is using the pear installer
Steps to install PHPUnit on windows.
1 ) On ‘C’ drive create a folder named ‘php5’
2 )Then on command prompt type:
pear upgrade pear
2 ) Once PEAR  is updated, on command prompt type:
pear channel-discover components.ez.no
pear channel-discover pear.phpunit.de
pear channel-discover pear.symfony-project.com
4 )Finally type:
pear install –alldeps   pear/phpunit2
This will install phpunit with all the required dependencies.
You might face couple of issues while installing this.  In that case please write to me and I shall be more than happy to help you.
So those were the steps to install PHPUNIT on windows. I have not tried this on the linux , but I believe the command ‘s will be similar. I will publish if I happen to install PHPUNIT on Linux.
Now let me start writing few basic test cases to show how PHPUNIT works.
The following is the basic example testing the size of the array
<?php
require_once ‘PHPUnit2/Framework/TestCase.php’;
class ArrayTest extends PHPUnit2_Framework_TestCase {
public function testNewArrayIsEmpty() {
// Create the Array fixture.
$fixture = Array();
// Assert that the size of the Array fixture is 0.
$this->assertEquals(0, sizeof($fixture));
}
public function testArrayContainsAnElement() {
// Create the Array fixture.
$fixture = Array();
// Add an element to the Array fixture.
$fixture[] = ‘Element’;
// Assert that the size of the Array fixture is 1.
$this->assertEquals(1, sizeof($fixture));
}
}
?>
The test for a class named  “Xyz” go into a class “XyzTest”
“XyzTest” is inherited from the base class  PHPUnit2_Framework_TestCase.
All the tests are public methods and it expects no parameters.
It’s a good practice to give the test method name as what we are testing in that method. In the above example I am testing if the array is empty, so my method name would ideally be testNewArrayIsEmpty.
Inside the test, assertion methods such as assertEquals() assert that an actual value matches an expected value.
Now to run this test you need to first get into the folder where you save this file .
After that use the following command
C:\wamp\bin\php\php5.3.0> phpunit ArrayTest
Here ArrayTest is the name of the Php file(ArrayTest.php)
After you run this you get the following screen
PHPUnit 2.3.0 by Sebastian Bergmann.
..
Time: 0.067288
OK (2 tests)
For  each test cases when you run them ,phpunit  command line print characters to display status the status .
. This is Printed when the test succeeds.
F This is Printed when an assertion fails while running the test method.
E This is Printed when an error occurs while running the test method.
I This Printed when the test is marked as being incomplete or not yet implemented.
There is a difference between Failure and Error . Failure is basically violated assertion and error is unexpected exception of PHP error.
Now lets make this test fail . So what I will do is I will insert an element to an array and try to assert  it to 0 instead of 1.
So my test case would be
public function testArrayContainsAnElement() {
// Create the Array fixture.
$fixture = Array();
// Add an element to the Array fixture.
$fixture[] = ‘Element’;
// Assert that the size of the Array fixture is 1.
$this->assertEquals(0, sizeof($fixture));
}
C:\wamp\bin\php\php5.3.0> phpunit ArrayTest
PHPUnit 2.3.0 by Sebastian Bergmann.
.F
Time: 0.001147
There was 1 failure:
1) testArrayContainsAnElement(ArrayTest)
expected same: <0> was not: <1>
/home/siyam/ArrayTest.php:21
FAILURES!!!
Tests run: 2, Failures: 1, Errors: 0, Incomplete Tests: 0.
As you can see that my test is complete but I have the .F  symbol . That means my assertion is failed.
So that was the simple test cases using PHPUNIT . As we see that we have a array called fixture which is used in both the test methods. So we can eliminate this code duplication  in our test . PHPunit invokes a test method before it runs any test . That method is setup(). So we can use this method to create objects against which we test .Once the test method finished running irrespective of test method failing or passing PHPUnit invokes another template method called tearDown(). In this method you can clean the objects that you have used.
So using the template method we can refactor  our test cases as follows
<?php
require_once ‘PHPUnit2/Framework/TestCase.php’;
class ArrayTest extends PHPUnit2_Framework_TestCase {
protected $fixture;
protected function setUp() {
// Create the Array fixture.
$this->fixture = Array();
}
public function testNewArrayIsEmpty() {
// Assert that the size of the Array fixture is 0.
$this->assertEquals(0, sizeof($this->fixture));
}
public function testArrayContainsAnElement() {
// Add an element to the Array fixture.
$this->fixture[] = ‘Element’;
// Assert that the size of the Array fixture is 1.
$this->assertEquals(1, sizeof($this->fixture));
}
}
?>
So that’s it for this article. I hope this article at least gets you started. I will write more about unit testing in my future articles. Its wide topic and I can cover a lot.
Happy Coding 

The best and easiest way to install PHPUNIT is using the pear installer

Steps to install PHPUnit on windows.

1 ) On ‘C’ drive create a folder named ‘php5’

2 )Then on command prompt type:

pear upgrade pear

2 ) Once PEAR  is updated, on command prompt type:

pear channel-discover components.ez.no

pear channel-discover pear.phpunit.de

pear channel-discover pear.symfony-project.com

4 )Finally type:

pear install –alldeps   pear/phpunit2

This will install phpunit with all the required dependencies.

You might face couple of issues while installing this.  In that case please write to me and I shall be more than happy to help you.

So those were the steps to install PHPUNIT on windows. I have not tried this on the linux , but I believe the command ‘s will be similar. I will publish if I happen to install PHPUNIT on Linux.

Now let me start writing few basic test cases to show how PHPUNIT works.

The following is the basic example testing the size of the array

<?php

require_once ‘PHPUnit2/Framework/TestCase.php’;

class ArrayTest extends PHPUnit2_Framework_TestCase {

public function testNewArrayIsEmpty() {

// Create the Array fixture.

$fixture = Array();

// Assert that the size of the Array fixture is 0.

$this->assertEquals(0, sizeof($fixture));

}

public function testArrayContainsAnElement() {

// Create the Array fixture.

$fixture = Array();

// Add an element to the Array fixture.

$fixture[] = ‘Element’;

// Assert that the size of the Array fixture is 1.

$this->assertEquals(1, sizeof($fixture));

}

}

?>

The test for a class named  “Xyz” go into a class “XyzTest

“XyzTest” is inherited from the base class  PHPUnit2_Framework_TestCase.

All the tests are public methods and it expects no parameters.

It’s a good practice to give the test method name as what we are testing in that method. In the above example I am testing if the array is empty, so my method name would ideally be testNewArrayIsEmpty.

Inside the test, assertion methods such as assertEquals() assert that an actual value matches an expected value.

Now to run this test you need to first get into the folder where you save this file .

After that use the following command

C:\wamp\bin\php\php5.3.0> phpunit ArrayTest

Here ArrayTest is the name of the Php file(ArrayTest.php)

After you run this you get the following screen

PHPUnit 2.3.0 by Sebastian Bergmann.

..

Time: 0.067288

OK (2 tests)

For  each test cases when you run them ,phpunit  command line print characters to display status the status .

. This is Printed when the test succeeds.

F This is Printed when an assertion fails while running the test method.

E This is Printed when an error occurs while running the test method.

I This Printed when the test is marked as being incomplete or not yet implemented.

There is a difference between Failure and Error . Failure is basically violated assertion and error is unexpected exception of PHP error.

Now lets make this test fail . So what I will do is I will insert an element to an array and try to assert  it to 0 instead of 1.

So my test case would be

public function testArrayContainsAnElement() {

// Create the Array fixture.

$fixture = Array();

// Add an element to the Array fixture.

$fixture[] = ‘Element’;

// Assert that the size of the Array fixture is 1.

$this->assertEquals(0, sizeof($fixture));

}

C:\wamp\bin\php\php5.3.0> phpunit ArrayTest

PHPUnit 2.3.0 by Sebastian Bergmann.

.F

Time: 0.001147

There was 1 failure:

1) testArrayContainsAnElement(ArrayTest)

expected same: <0> was not: <1>

/home/siyam/ArrayTest.php:21

FAILURES!!!

Tests run: 2, Failures: 1, Errors: 0, Incomplete Tests: 0.
As you can see that my test is complete but I have the .F  symbol . That means my assertion is failed.

So that was the simple test cases using PHPUNIT . As we see that we have a array called fixture which is used in both the test methods. So we can eliminate this code duplication  in our test . PHPunit invokes a test method before it runs any test . That method is setup(). So we can use this method to create objects against which we test .Once the test method finished running irrespective of test method failing or passing PHPUnit invokes another template method called tearDown(). In this method you can clean the objects that you have used.

So using the template method we can refactor  our test cases as follows

<?php

require_once ‘PHPUnit2/Framework/TestCase.php’;

class ArrayTest extends PHPUnit2_Framework_TestCase {

protected $fixture;

protected function setUp() {

// Create the Array fixture.

$this->fixture = Array();

}

public function testNewArrayIsEmpty() {

// Assert that the size of the Array fixture is 0.

$this->assertEquals(0, sizeof($this->fixture));

}

public function testArrayContainsAnElement() {

// Add an element to the Array fixture.

$this->fixture[] = ‘Element’;

// Assert that the size of the Array fixture is 1.

$this->assertEquals(1, sizeof($this->fixture));

}

}

?>

So that’s it for this article. I hope this article at least gets you started. I will write more about unit testing in my future articles. Its wide topic and I can cover a lot.

Happy Coding .

Category: PHP, Testing/QA  | Leave a Comment
Sunday, February 13th, 2011

In Prism, loosely coupled components in the application communicate with each other using a event aggregation service that the library provides. The event aggregator service uses a publish/subscribe mechanism for communication. The EventAggregator provides multicast publish/subscribe functionality. This means there can be multiple publishers that raise the same event and there can be multiple subscribers listening to the same event as given below.

EventAggregator_Image

In prism communication between publishers and subscribers is done by the CompositePresentationEvent class. This class maintains the list of subscribers and handles event dispatching to the subscribers.

The CompositePresentationEvent class is a generic class that requires the payload type to be defined as the generic type. This helps enforce, at compile time, that publishers and subscribers provide the correct methods for successful event connection.

Event creation is done by creating a class that inherits the CompositPresentationEvent class.

public class EmployeeAddedEvent : CompositePresentationEvent<Model.Employee> { }

Publishers raise an event by retrieving the event from the EventAggregator and calling the Publish method. To access the EventAggregator, you can use dependency injection by adding a parameter of type IEventAggregator to the class constructor. For e.g.

private void OnAddNewClicked()

{

AddNewEmployeeAndPassToEmployeeView();

}

private void AddNewEmployeeAndPassToEmployeeView()

{

Model.Employee employee = new Model.Employee

{

Id = Guid.NewGuid(),

FirstName = “New Employee”,

LastName = “Last Name”,

ChangedDate = DateTime.Now,

CreatedDate = DateTime.Now,

DateOfJoining = DateTime.Now

};

_eventAggregator.GetEvent<EmployeeAddedEvent>().Publish(employee);

}

Subscribers can enlist with an event using one of the Subscribe method overloads available on the CompositePresentationEvent class. In our sample, you can use the event subscription as

private void SubcribeToEmployeeAddedEvent(IEventAggregator eventAggregator)

{

EmployeeAddedEvent employeeAddedEvent = eventAggregator.GetEvent<EmployeeAddedEvent>();

if (_subscriptionToken != null)

employeeAddedEvent.Unsubscribe(_subscriptionToken);

_subscriptionToken = employeeAddedEvent.Subscribe(OnEmployeeAddedEvent, ThreadOption.UIThread, false);

}

public void OnEmployeeAddedEvent(Model.Employee employee)

{

Employees.Add(employee);

}

If your subscriber no longer wants to receive events, you can unsubscribe by using your subscriber’s handler or you can unsubscribe by using a subscription token.

The following code example shows how to directly unsubscribe to the handler.

employeeAddedEvent.Unsubscribe(OnEmployeeAddedEvent);

Author:
Wednesday, February 09th, 2011

 

This article briefly explains why documentation is required in development of software projects, what types of documents you should create and myth about agile documentation.

‘Working software over comprehensive documentation’ 2nd manifesto of agile software development (http://agilemanifesto.org/) .  In traditional approach, you will find most of documents shown in Fig-01 are created before the development phase (coding) starts.  The project starts with requirements phase, design phase etc each phase deliverables are just documents. Progress is ZERO until the coding phase starts. Documentation is not one time activity, you need to maintain it (update & reviewed) so more time & money spent.  Sometimes project fails due to hefty documentation i.e. exceeding project budget or delay in completion.

Do we need really need all the listed documents? NO, Travel light. We get more business value in working software than in comprehensive (broader in scope) documentation.  

waterfall-dox

Fig-01

 

Agile myth: Zero Documentation

Some believe that Agile doesn’t require (or, even, cannot support) documentation.  Agile manifesto never says documents are waste or not useful.  Agile documentation says: travel light (Write fewest documents), Just-in time, Update only when it hurts.  You may save time & cost without documents but the project may fail in long run i.e. when the project is given to another team for maintenance. In simple words, no projects should be developed without supporting documents.

Why Do People Document?

  • To support organizational memory

Working Software is Your Primary Goal.   An important implication is that we not only need to develop software, but we also need to develop the supporting documentation required to use, operate, support, and maintain the software over time. 

What type of documents do you need?

  1. Project Proposal

    Think about the environment before printing!

    Think about the environment before printing!

  2. Product Backlog: list of features to develop. Link features to use case doc
  3. Use case/User story/Feature Specs: covers
    1. Use case scenarios & screen prototype
    2. business rules & validation messages
    3. class diagram (nice to have)
  4. Design & Architecture document: consists of
    1. Technology, frameworks chosen for the projects
    2. Sequence diagram to explain execution flow
    3. Explanation on layers of architecture (mostly MVC2)
    4. How to develop & configure? Code snippets on view, controller, model, configuration files etc
    5. Non functional requirements
  5. Quality management:
    1. Defect tracker
    2. Functional test cases
  6. Build & Deployment document: covers
    1. System architecture/Deployment diagram
    2. Environment details e.g. IP details of DEV, TEST, UAT, PROD environments
    3. How to build & deploy?
    4. Labeling/Versioning strategy, SCM details
    5. Configuration Management details
    6. Post-deployment verifications
  7. Miscellaneous documents like
    1. Traceability matrix

I strongly encourage Product Owners to produce User Stories/Usecases/Functional Spec documents because they connect very deeply with the project, rest of the documents should be created & maintained by project team (Architects, Developers & Testers).

Also visit:

Category: Agile/Scrum  | 2 Comments
Wednesday, February 02nd, 2011

Authentication in Silverlight applications that use WCF RIA services can make use of the WCF RIA services authentication framework. WCF RIA Services builds upon the ASP.NET Membership framework by exposing the Membership framework to rich Internet clients through the authentication domain service. After adding an authentication domain service, you can enable the following functions:

  • Authentication – to verify a user’s credentials and mark the user as logged in or logged out.
  • Roles – to group users by responsibilities and grant resource permissions to authenticated members of a group.
  • Profiles – to retain properties for authenticated users and retrieve those properties in your application.

This post demonstrates how to enable user authentication in your prism application using RIA services.

RIA Services provides the authentication domain service template to facilitate authentication on the presentation tier. The authentication domain service derives the AuthenticationBase class which contains the profile properties for the authenticated user. This service is accessed via the WebContext class which is automatically generated by the RIA services. You can also create your custom implementation for the membership provider and configure the service to use this instead of the default provider.

For e.g.:

public class BlogsPrajeeshMembershipProvider : MembershipProvider

{

public override string ApplicationName

{

get

{

return “BlogsPrajeesh.PrismSamples”;

}

set { }

}

//Other methods…

public override bool ValidateUser(string username, string password)

{

if (username == “Prajeesh” && password == “Password”) return true;

return false;

}

}

Configuring the membership provider in the Web.config file.

<system.web>

<httpModules>

<add name=”DomainServiceModule” type=”System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ />

</httpModules>

<compilation debug=”true” targetFramework=”4.0″>

<assemblies>

<add assembly=”System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ />

</assemblies>

</compilation>

<authentication mode=”Forms” />

<membership defaultProvider=”BlogsPrajeeshMembershipProvider”>

<providers>

<add name=”BlogsPrajeeshMembershipProvider” type=”BlogsPrajeesh.PrismSamples.Web.BlogsPrajeeshMembershipProvider, BlogsPrajeesh.PrismSamples.Web”/>

</providers>

</membership>

</system.web>

To use this authentication service in the Silverlight client, configure the WebContext in App.xaml.cs file as

public App()

{

this.Startup += this.Application_Startup;

this.Exit += this.Application_Exit;

this.UnhandledException += this.Application_UnhandledException;

InitializeComponent();

WebContext context = new WebContext();

context.Authentication = new FormsAuthentication();

ApplicationLifetimeObjects.Add(context);

}

Later in the Shell

public Shell()

{

InitializeComponent();

this.Loaded += new RoutedEventHandler((x, y) =>

{

if (WebContext.Current.Authentication.User != null && !WebContext.Current.Authentication.User.Identity.IsAuthenticated)

{

RegionManager.Regions["LoginRegion"].Add(LoginView, “LoginView”);

RegionManager.Regions["LoginRegion"].Activate(LoginView);

}

});

}

The LoginViewModel code that authenticates the user

[Export(typeof(LoginViewModel))]

[PartCreationPolicy(CreationPolicy.NonShared)]

public class LoginViewModel : NotificationObject

{

[ImportingConstructor]

public LoginViewModel(IRegionManager regionManager)

{

_regionManager = regionManager;

LoginCommand = new DelegateCommand(() => PerformLogin());

this.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler((x, y) => RaiseCommandChanged());

}

private void RaiseCommandChanged()

{

LoginCommand.RaiseCanExecuteChanged();

}

private void PerformLogin()

{

var webContext = WebContext.Current;

webContext.Authentication.Login(“Prajeesh”, “Password”);

webContext.Authentication.LoggedIn += new EventHandler<System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationEventArgs>((x, y) =>

{

var loginView = _regionManager.Regions["LoginRegion"].GetView(“LoginView”);

_regionManager.Regions["LoginRegion"].Remove(loginView);

});

}

//Other methods…

}