preload
Feb 13

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!

Follow me on twitter @PerOla

Share & enjoy
You can subscribe to my comments feed to keep track of new comments.

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

  1. Brian says:

    I receive an error: “Error 403: forbidden access denied” error. Is there a configuration that I missed?

  2. Hi Brian,
    Does your service work when you run it locally?
    Where do you get this Error 403? Is it when you run http://………../Service1.cs in your browser?

  3. Kyle says:

    Hello,

    I’ve followed this tutorial and it is very insightful, but when I go to test the login feature, this line:

    string _result = ((string)(base.EndInvoke(“LoginUser”, _args, result)));

    gives this error:

    The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

    Is this something you can help me with? Or is this something that is unique to my situation? I’ll keep looking just in case… Thanks!

  4. Hi Kyle,

    I did never experience this problem. The first thing I would do is to verify that the methods in your WCF services are working.
    You can also have a look at some articles I wrote for DZone covering the same area. I think I describe more in detail how to actually test your services before consuming them in WP7 there: http://breathingtech.com/2011/push-notifications-for-windows-phone-7-using-sql-azure-and-cloud-services/

  5. rock says:

    Hello,
    I am following the Tutotial, however, I encounter the same problem as Kyle which is I cannot login.
    I tried to deployed onto Azure, then the result would be like


    The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.”

  6. Ayat says:

    hello i followed this tutourial but i used just the logIn service ,and i face a problem that it doesnt give me any thing and returns to the first page that appear when run the project9page that contain the name of the app ,IE icon ,and the setting icon) i wish you undestand me.

  7. Ayat says:

    I followed this tutourial but i used just the logIn service and the problem that it doesn’t give the message that i wait ,the result that it returns to the main page of the phone it self that has (the name of the application,IE icon,and the Settings of the phone.)

  8. David says:

    Fantastic tutorial, more clear both than msdn docs and azure wp7 toolkit samples !!
    Worked at first attempt.
    Thank you!!

  9. David says:

    Only the deploy section does not correspond, maybe new sdk/vs2010 updates changed wizards a little.
    I only selected ‘Publish’ from the popup menu right clicking the WindowAzureProject1 icon, following the wizard.
    The steps were little different from what is described in this last section, but worked perfectly, I have the sample WP app connected to online Azure now (and I can see the new records directly from Management Studio :)

  10. Hi David,

    Thank you for the good feedback. I guess the SDK has changed a little since I wrote the post. There are also two different ways you can publish Azure projects. One wizard based (they way you did it) and one more manual way as I described.

  11. Hi Kyle, Rock, Ayat

    It has been quite a while since I did this now and unfortunately I do not have the answer to your issues. The tutorial should work if you follow it step by step, maybe try starting from scratch again?

  12. tekin says:

    İ didn’t find this step “select “Create service package only” and click “OK”….”

  13. tekin,
    The implementation details have changed a bit since this article were written. You can try doing what David explained earlier in the comments.

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

  1. […] Как использовать WCF службы для доступа к SQL Azure DB в Windows Phone 7 приложениях Части 1, 2, 3, 4 […]

Leave a Reply

Subscribe to my comments feed

Subscribe to my feeds Follow me on Twitter
DZone MVB