MOBILE

Windows Phone 7 Development : Creating a Cloud Service to Access the Cloud Database (part 1) - Generating an Object Model to Access the Cloud Database

1/17/2011 9:14:19 AM

You will be creating a WCF service called NotepadService that will be consumed by the Windows Phone Notepad application. Think of NotepadService as the layer that provides managed APIs to the Notepad application. NotepadService will utilize the Entity Framework to generate object models based on the database tables, and it will also generate a persistence layer that performs the database operations, which otherwise you would have to code yourself. Finally, the steps will provide you with instructions on creating and deploying NotepadService to Windows Azure. You will be creating a WCF Azure service and running it from your machine, and then you will learn to package and deploy the project to the Azure cloud, where you will be able to configure to have multiple services run if your application demand increases.

1. Creating a Windows Azure Project

You will be creating a Windows Azure NotepadService project in Visual Studio in the following steps. In order to create Azure services, you would need to download Azure tools and SDK from www.microsoft.com/windowsazure/windowsazure/default.aspx.

  1. Create a new Windows Phone Application by selecting File => New Project on the Visual Studio command menu. Select the Cloud installed template on the left, and choose Windows Azure Cloud Service from the list on the left, as shown in Figure 1. Name the Azure service "NotepadService" and click OK.

    Figure 1. Windows Azure Cloud Service project
  2. You will be prompted to select the type of role. Notice here that if you want to host the web project, you would need to select ASP.NET Web Role. For Notepad WCF service, you will need to select WCF Service Web Role, as shown in Figure 3-18, and click the arrow pointing to the left. In Cloud Service Solution, you will see WCFServiceWebRole, and if you hover your mouse over the item, you will see that a little pencil icon appears. Click the pencil icon and change the name to NotepadServiceRole, as also shown in Figure 2.

    Figure 2. Selecting WCF Service Web Role

2. Generating an Object Model to Access the Cloud Database

Now that we have basic plumbing for implementing a WCF service, it is a good time to implement a persistence layer that allows you to interact with the database. Entity Framework will act as an object-relational mapping tool that will take database tables and create equivalent object models and many of the tedious tasks of coding methods, like add, delete, update, and search, which can be easily handled by Entity Framework.

When you complete this section, you will be creating two object models, User and Note, which you can work directly in the code. Also Entity Framework will provide the ability to save these models directly back to the database.

In the following steps, you will learn to add an Entity Framework item to the project and then connect to NotepadDB in SQL Azure and generate object models.

  1. Right-click the NotepadServiceRole project found in Solution Explorer, and choose Add => New Item.

  2. Click the Data from Installed Templates list, choose ADO.NET Entity Data Model, and name the model NotepadService.edmx, as shown in Figure 3.

    Figure 3. Adding Entity Framework
  3. You will be prompted with the Entity Data Model Wizard, as shown in Figure 4. Click the Next button.

    Figure 4. Entity Data Model Wizard
  4. Click the "New Connection..." button, and when Choose Data Source appears, select Microsoft SQL Server from the list, as shown in Figure 5. Click the Continue button.

    Figure 5. Choose Data Source window
  5. You will be prompted with a Connection Properties window. In the service name, put the SQL Azure server name that you acquired from the previous steps and enter "NotepadAdmin" and "P@ssword" as your username and password. Then from the "Select or enter database name" drop-down, select NotepadDB, as shown in Figure 6.

    Figure 6. Connection Properties window
  6. Click the OK button, and you will return to the Entity Data Model Wizard window. Select Yes, include the sensitive data in the connection string radio button, and click the Next button.

  7. If you expand the tables, you will see the two tables (Note and User) that you created previously. Select both of the tables, as shown in Figure 7.

    Figure 7. Choosing the database objects
  8. Take the default option for everything else, click the Finish button, and you will return to the Visual Studio project and see Notepad.edmx, which contains two object models: User and Note, as shown in Figure 8.

    Figure 8. Entity model Notepad.edmx

You now have User and Note object models that you can work with in your NotepadService. In the next section, you will be preparing NotepadService, which will implement simple create, read, update, and delete operations using the entity model that you generated in this section.

Other  
  •  Windows Phone 7 Development : Using Cloud Services As Data Stores - Creating a Cloud Database
  •  iPhone Application Development : Working with Text, Keyboards, and Buttons (part 5) - Implementing the View Controller Logic
  •  iPhone Application Development : Working with Text, Keyboards, and Buttons (part 4) - Hiding the Keyboard
  •  iPhone Application Development : Working with Text, Keyboards, and Buttons (part 3) - Creating Styled Buttons
  •  iPhone Application Development : Working with Text, Keyboards, and Buttons (part 2) - Adding Text Views
  •  iPhone Application Development : Working with Text, Keyboards, and Buttons (part 1) - Adding Text Fields
  •  Building Android Apps : Controlling the Phone with JavaScript (part 3) - Accelerometer
  •  Building Android Apps : Controlling the Phone with JavaScript (part 2) - Geolocation
  •  Building Android Apps : Controlling the Phone with JavaScript (part 1) - Beep, Vibrate, and Alert
  •  Building Your First Windows Phone 7 Application (part 5) - Styling Your Application
  •  Building Your First Windows Phone 7 Application (part 4) - Customizing Your First Windows Phone Application
  •  Building Your First Windows Phone 7 Application (part 3) - Writing Your First Windows Phone Code
  •  Building Your First Windows Phone 7 Application (part 2) - Using Your First Windows Phone Silverlight Controls
  •  Building Your First Windows Phone 7 Application (part 1) - Creating a Windows Phone Project
  •  Introducing Windows Phone 7 and the Windows Phone Platform
  •  Windows Phone Application Platform
  •  iPhone Application Development : Basic User Input and Output
  •  Mobile Phone Game Programming : A Quick J2ME Primer
  •  Mobile Phone Game Programming : Java As a Mobile Game Platform
  •  Mobile Phone Game Programming : Getting to Know Mobile Platforms
  •  
    Most View
    Big Shot Rivals: Sony vs. Samsung
    500px - The Stunning Photography Gallery Comes To iPhone
    The Complete Guide To Photography On Your Mac! (Part 1)
    Installing the HP-UX 11i Operating Environment (part 1) - Integrity Early Boot and Begin Loading HP-UX from an Ignite-UX Server, Integrity Early Boot and Begin Loading HP-UX from Media
    Maingear Alpha 24 Super Stock - No Retreat, No Surrender
    Synology 4-Bay NAS: Three Models Review (Part 4)
    Get Yourself A Portable DAC
    HTC Butterfly - Smartphone With Full HD Display
    Windows 8 Explorer : Diagnosis and Recovery - The Processes Tab
    Microsoft Dynamics Sure Step 2010 : A repeatable process for the sales teams (part 2)
    Top 10
    Zotac GeForce GTX Titan Black
    Toshiba Q Series 256GB and 512GB, Toshiba Q Series Pro 256GB
    The Gaming Mouse: Ozone Neon
    SanDisk Ultra Plus 256GB And X110 256GB
    SanDisk Extreme II 480GB, Plextor M5 Pro Extreme 256GB and 512GB
    Samsung SSD 840 Evo 250GB, 500GB And 1TB
    PNY XLR8 240GB and XLR8 PRO 240GB
    OCZ Vector 150 240GB And 480GB, And Vertex 460 240GB
    Nvidia GeForce GTX 750 Ti
    Nokia Lumia 1020 41 Megapixels Of Awesome