Random Ramblings About Making Games and Stuff from Cloud

Posts tagged ‘WP7’

Things I learned building OData service to Azure and using WP7 as client

I wanted to build an Windows Phone 7 app called “Stuff I Like”. App would have OData service running in Azure and client that would cache and sync to that service. In previous post I wrote about stuff that I learned building the WP7 app. In this part I will reveal my findings on the service side of things. In the next post I will dwell into Authentication side of the app.

If you are planning to add Federated Authentication using Azure Access Control service then you might want to start by building authentication first. For me it was waaaay easier to add normal aps web page add authentication to that and add WCF data service after login worked. For you I would recommend downloading Azure Training Kit: http://www.microsoft.com/en-us/download/details.aspx?id=8396 and completing Lab Exercise http://msdn.microsoft.com/en-us/identitytrainingcourse_acsandwindowsphone7.aspx

Now back to business.

When I followed this Data service in the cloud http://msdn.microsoft.com/en-us/data/gg192994. I decided to design the data model using visual studio design tool. After playing a round with the tool I managed to “draw” data model and after that it was just a matter of syncing it to Database.

This is how I draw the data model

After syncing above data model into database, setting up the service and running it I quickly found that my WCF Data Services where not working at all. Message “The server encountered an error processing the request. See server logs for more details.” was shown to me quite frequently. Well “the bug” was quite simple to fix and these debugging instructions helped me a lot http://www.bondigeek.com/blog/2010/12/11/debugging-wcf-data-services:

  1. A missing SetEntitySetAccessRule
  2. A missing pluralisation on the SetEntitySetAccessRule
  3. A missing SetServiceOperationAccessRule

After Debugged EntityAccessRules with simple “*” allowRead just to check that I had not made a typo I quickly found out that I indeed had 😦 So I after I fixed a typo in EdmRelationshipAttribute and it caused the exception. After that stupid mistake things started to look better.

If you need more instructions on how to turn on debugging messages then just follow these instructions:

This is how my service looked after I finally got it running

After I managed to get service defined and running I took a second to make OData feed a bit more readable so that you can consume your OData feed using Explorer and other browsers. http://msdn.microsoft.com/en-us/library/ee373839.aspx

This is how OData feed looks before you tweak it a bit.

For some reason I managed to first add “m:FC_TargetPath” and similar properties to wrong xml element. So make sure you scroll down the file and add it to correct place 🙂

This is how OData feed will look when you tweak it a bit

Another thing that took me couple of hours to figure out was that Explorer does not show all OData results in consistent way. So before you start heavily debugging check the returned html page source code and you should see expected result in XML format. OR you could use another browser. For example this call did not seem to return anything http://localhost:57510/WcfDataServiceStuffILike.svc/StuffSet(guid’cf1bfd2f-99f3-4047-99f8-22bc1aad1b99′)/GategorySet until I checked the source code of this page.

So that’s it. Using Visual Studio this was quite easy and I actually spent most of my time figuring out why some configuration did not work than making the code.  This might be due to the fact that I have “unclean” dev environment or I made lots of changes to above demos while I followed them. This was mainly due to the fact that I wanted to build my own app and not simply type in demos and labs.

I bet If you build your dev environment correctly and follow the labs and demos to the letter you won’t see as many problems that I witnessed. But where is the fun in that 😉

Advertisements

Things I Learned using Windows Phone 7 devkit

I recently started playing with around with Windows Phone 7 devkit and found it to be surprisingly productive tool set. I managed to develop a simple app within couple of weekends with almost zero previous knowledge on WP7 programming. I learned a couple of things on the way and wanted to tell them to you.

What I did was I started with installing Expression Blend, Visual Studio 2010 and WP7 SDK. I made UI using Blend and did the coding with Visual Studio. Benefits of this were near WYSIWYG experience with WP7 UI and no broken XAML during development.

And now the tips what I learned:

  • Start with the data. Design the data model first because it will help you working with Expression Blend. Make design time data for your blend project and how to trouple shoot it.
  • Trust the Blend. Use it and learn it. I admit that it took good amount of time to find how to make all of the stuff. Some weirdness that I found hard to locate:
    • Databinding to UI items
    • Table you need to add row and column definitions (found under layout)
    • To add more complex list box items than just plain text you need to edit List box item template. Found under list box right mouse click, edit generated Items, edit current.
    • This is how to create menu context items.
    • This is how to create application bar.
    • Use system styles in text boxes PhoneForeground etc. So if user changes the phone theme your app will do the same.
    • DO NOT apply system styles to list boxes! It will break selected styles. Adjust the font size and font or make you own styles that only change font and font size. Otherwise you will spend time on implementing list box selected item visualization.
  • BIND UI to data. Seriously this will help a lot. You should not assign data to UI components. All my weird UI bugs where data is not updating where result of not doing the BIND correctly.
  • Test BIND working on your data periodically. This is because you want BINDING to work.
  • Make your data implement data as INotifyPropertyChanged change so that when data changes it automatically changes on UI.
  • Define data as serialisable.
  • Icons where to find default icons: “C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Icons”
  • How to make clear enough icons. You can also use Inkscape with 1028×1028 canvas and convert image to png.

Well that’s for now. I will make follow up posts on things I learn during my ventures on WP7 world.

ps. Here are some screenshots on the app I am working on. Its called “Stuff I Like” and its a simple tool for keeping track on stuff I hear about and might like.

%d bloggers like this: