Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to use WCF services to access SQL Azure Database from Windows Phone 7 app – Part 4

DZone's Guide to

How to use WCF services to access SQL Azure Database from Windows Phone 7 app – Part 4

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

This is the last part in a series of four and will step by step explain how to use WCF services to access SQL Azure Database from Windows Phone 7 app. As an example I will develop a Windows Phone app where the user can create an account and later on log in to the account by user name and password. The accounts are saved in SQL Azure and I am using WCF for communication between the WP7 app and SQL Azure Database.

The book Beginning Windows Phone 7 Development has a very detailed chapter about using SQL Azure Database.

Part 1: Signing up to Windows Azure and create your SQL Azure Database

Part 2: Creating a cloud service (WCF service) to connect to the SQL Azure Database

Part 3: Creating a Windows Phone 7 app using WCF to connect to the SQL Azure Database

Part 4: Deploying the WCF service to Windows Azure

Create a service package

Go to your service project in Visual Studio 2010. Right click the project in the solution explorer and click “Publish”, select “Create service package only” and click “OK”. A file explorer window will pop up with the service package files that got created. Keep this window open, you need to browse to these files later.

Create a new hosted service

Go to https://windows.azure.com and login with the account you used when signing up for the SQL Azure. Click “New Hosted Service” and a pup up window will be displayed. Select the subscription you created for the SQL Azure database, enter a name for the service and a url prefix. Select a region, deploy to Stage and give it a description. Now you need to browse to the two files that you created when you published the service in the step above and click “OK”.  Your service will be validated and created (might take a while).

Using the hosted service in your Windows Phone project

In the Management Portal for Windows Azure you will now see the service you deployed in Hosted Services. Click the deployment and you can see information about it on the right side. Copy the URL you see in the DNS name field. Go to your Windows Phone project and open ServiceReferences.ClientConfig. You can see that the end point address in this file points to the local service you ran earlier. Replace the end point address with the DNS name you just copied. NB. the address must end with “/Service1.cs”.

If your hosted services have status Ready you can now run your WP7 application and it will use the hosted service.

Next step

If you have followed the four parts in this series you now have a SQL Azure Database, Windows Azure hosted WCF service and a WP7 application consuming the hosted service. You know have a good base for continuing  developing and building complex applications where storage and services are placed in the Cloud. Your apps will be able to scale unlimited and you will only pay for your current usage. Happy coding!

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:

Published at DZone with permission of Per Ola Sæther, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}