Windows Phone – Use REST WCF Service

Today when I play around with development in Windows Phone 7. I would like to check if I can access WCF REST Service which I discussed before in this post http://hintdesk.com/wcf-silverlight-access-wcf-rest-services-with-silverlight/ . To start with the development in Windows Phone 7 you need to download set of development tools here http://www.microsoft.com/downloads/details.aspx?FamilyID=2338b5d1-79d8-46af-b828-380b0f854203&displaylang=en . This set contains of
– Visual Studio 2010 Express for Windows Phone CTP
– Windows Phone Emulator CTP
– Silverlight for Windows Phone CTP
– XNA 4.0 Game Studio CTP
This packet is about 350 MB and can be installed parallel with Visual Studio 2008 SP1 and .Net Framework 3.5. When I try to move the example of the old post to Windows Phone 7, I think it must be very simple because the old example bases on Silverlight and Windows Phone 7 uses Silverlight as its default template and I am right. During the moving, I just need to copy and paste the code behind without needing to change anything. However some of components in normal Silverlight are not available, for example Label and DataGrid. The label can be easily replaced by a TextBlock but we need more work to make a control to replace DataGrid. I make a snapshot of available controls in image below

I decide to use ListBox to replace DataGrid and edit the ItemTemplate of ListBox so that I can show all information of data object

<ListBox ItemsSource="{Binding}" x:Name="dgStudents" Margin="10,60,6,228">
	<ListBox.ItemTemplate>
		<DataTemplate>
			<StackPanel Orientation="Horizontal">
				<TextBlock Text="{Binding StudentID}" Margin="0,0,0,0"></TextBlock>
				<TextBlock Text="{Binding Chair}" Margin="40,0,0,0"></TextBlock>
				<TextBlock Text="{Binding AverageNote}" Margin="40,0,0,0"></TextBlock>
				<TextBlock Text="{Binding StudentName}" Margin="40,0,0,0"></TextBlock>
			</StackPanel>
		</DataTemplate>
	</ListBox.ItemTemplate>
</ListBox>

The rest of code is completely same as old example. Just need to adjust the GUI so that it fits the screen of Windows Phone 7.

You can see that I try to size the controls as small as possible and leave the area near bottom blank as much as possible because when I try to input data, the keyboard will pop up from the bottom and cover our controls. The complete source code of this example you can download here “WCF REST and Windows Phone 7“.

The complete tool set for developing with Windows Phone is list below. Enjoy programming
– Windows Phone Developer Tools
http://www.microsoft.com/downloads/details.aspx?FamilyID=2338b5d1-79d8-46af-b828-380b0f854203&displaylang=en
– Expression Blend 4 Beta
http://www.microsoft.com/downloads/details.aspx?FamilyID=6f014e07-0053-4aca-84a7-cd82f9aa989f&displaylang=en
– Expression Blend Add-in Preview for Windows Phone
http://www.microsoft.com/downloads/details.aspx?FamilyID=47f5c718-9dec-4557-9687-619c0fdd3d4f&displaylang=en
– Expression Blend SDK Preview for Windows Phone
http://www.microsoft.com/downloads/details.aspx?FamilyID=86370108-4c14-42ee-8855-226e5dd9b85b&displaylang=en

Leave a Reply

Your email address will not be published. Required fields are marked *