I will continue the more practical part of this series by showing how the new mobile architecture looks in code, and if you want some background, please see the previous parts:
- Part 1 was a general introduction
- Part 2 talked about the changes in the lower tiers (logic + data, LINQ2SQL)
- Part 3 discussed the changes in communication (WCF)
- Part 4 covered important stuff in the user interface (MVC)
- Part 5 summarized the theory and outlined the new architecture
- Part 6 started the walkthrough of the architecture code by looking at the business domain
The implemented architecture is published on CodePlex in a project called Windows Mobile Architecture Blueprint, and this means that you can access the full source code as well as discuss it, come with suggested improvements, etc. As I walk you through the creation of the architecture, I suggest you keep the source code handy to check out more details.
The next step in building the architecture is to create the service interface (i.e. the service), and therefore I have added a new "WCF Service Application" project called Blueprint.Facade to the solution that already included the business domain project (Blueprint.Domain). My first service will be publishing the very simple functionality that the business domain provides (the ability to retrieve all categories from the database). First, I have renamed the service interface to IService and the service implementation to Service (removed the "1" at the end on both), and here you need to make sure that all references are updated (four occurences in the web.config file and don't forget the one in Service.svc). The implementation of the service interface (IService.cs) can be done like this...
[ServiceContract]
public interface IService
{
[OperationContract]
Category[] GetCategories();
}
...and with a reference to the business domain project, the service implementation (Service.svc.cs) can be implemented with this code...
public class Service : IService
{
public Category[] GetCategories()
{
using(NorthwindDataContext dc = new NorthwindDataContext())
return dc.GetCategories();
}
}
...to complete the implementation of the service. When the project is built and run, the WCF is ready to be consumed, and therefore it's a good idea to remember the URL to the service as we will need it in the next post when we will look at how this service can be consumed from a mobile client application.