IT tutorials
 
Mobile
 

Windows Phone 8 : Walking Through the Bookshop Sample Application (part 5) - Overview of the Sample Bookshop WCF Service

4/16/2014 2:28:00 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Overview of the Sample Bookshop WCF Service

The Bookshop demo application includes a server-side component, which is used by both the ProductsViewModel and ProductDetailsViewModel classes, providing the application with a set of products to display. The server-side component is fairly arbitrary and is presented here merely for the sake of completeness.

The WCF service is called BookshopService and resides in the WPUnleashed.Web project of the downloadable sample code (see Listing 8).

LISTING 8. BookshopService Class


[AspNetCompatibilityRequirements(
    RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class BookshopService : IBookshopService
{
    public IEnumerable<Product> GetProducts()
    {
        return ProductManager.Products;
    }

    public Product GetProductById(int productId)
    {
        return ProductManager.GetProductById(productId);
    }
}


The BookshopService exposes static methods of the ProductManager class, shown in Listing 9. The ProductManager class creates an XDocument instance, using an XML file, to populate a list of Products.

LISTING 9. ProductManager Class


public static class ProductManager
{
    static readonly List<Product> products = new List<Product>();

    public static IEnumerable<Product> Products
    {
        get
        {
            return products;
        }
    }

    static ProductManager()
    {
        string path = HttpContext.Current.Server.MapPath(
            "~/Services/Bookshop/Products.xml");
        XDocument document = XDocument.Load(path);
        foreach (XElement element in
            document.Element("Products").Elements("Product"))
        {
            var product = new Product(element);
            product.SmallImageUri
                = ServerUtility.ResolveServerUrl(product.SmallImageUri);
            product.LargeImageUri
                = ServerUtility.ResolveServerUrl(product.LargeImageUri);
            products.Add(product);
        }
    }

    public static Product GetProductById(int id)
    {
        if (id < 0 || id > products.Count)
        {
            throw new ArgumentOutOfRangeException("id");
        }
        return products[id - 1];
    }
}


The Product class contains the properties that are used to display each book’s details, such as Title and Author. The Product class also knows how to populate itself from an XElement. The explicit casting operators of the XElement class make it easy to extract the values to the Product properties, as shown in the following excerpt from the Product class:

public Product(XElement element)
{
    if (element == null)
    {
        throw new ArgumentNullException("element");
    }
    Id = (int)element.Element("Id");
    Title = (string)element.Element("Title");
    Author = (string)element.Element("Author");
    Description = (string)element.Element("Description");
    SmallImageUri = (string)element.Element("SmallImageUri");
    LargeImageUri = (string)element.Element("LargeImageUri");
    Price = (double)element.Element("Price");
    Isbn10 = (string)element.Element("ISBN-10");
    Isbn13 = (string)element.Element("ISBN-13");
    ExternalUrl = (string)element.Element("ExternalUrl");
}

 
Others
 
- Windows Phone 8 : Walking Through the Bookshop Sample Application (part 4) - Image Caching
- Windows Phone 8 : Walking Through the Bookshop Sample Application (part 3) - Design-Time Data
- Windows Phone 8 : Walking Through the Bookshop Sample Application (part 2) - Displaying the Product List
- Windows Phone 8 : Walking Through the Bookshop Sample Application (part 1)
- Windows Phone 8 : Page Navigation - Creating an Application Splash Screen
- Windows Phone 8 : Page Navigation - Page Redirection, Hardware Back Button
- Windows Phone 8 : Page Navigation - Canceling Navigation, Cross-Page Communication
- Windows Phone 8 : Page Navigation - Navigation Using the NavigationService, Handling Page Navigation
- Windows Phone 8 : Page Navigation - URI Mapping
- Windows Phone 8 : Page Navigation - Passing Page Arguments Using Query Strings
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us