Windows Phone 7 (WP7) was out last month. It is a successor to Microsoft’s Mobile platform but completely different from Windows Mobile 6.5 or earlier version. That means no backward compatibility. The programming use Silverlight. For the detailed architecture overview of WP7, there is a great reference here: ecn.channel9.msdn.com/o9/te/NorthAmerica/2010/pptx/WPH313.pptx
The service is the same as the last post (Oct. 25).
Here is the code on the WP7(everything in Silverlight is synchronized):
private void btnSearch_Click(object sender, RoutedEventArgs e){if (txtSearch.Text != ""){string url = "http://localhost:8000/Users/Eric";WebClient proxy = new WebClient();proxy.OpenReadCompleted += new OpenReadCompletedEventHandler(proxy_OpenReadCompleted);proxy.OpenReadAsync(new Uri(url));}}
void proxy_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e){DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(User));User foundUser = ser.ReadObject(e.Result) as User;if (null != foundUser){txtUser.Text = foundUser.Name;}}
These two namespaces need to be included for Json serialization:
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
No comments:
Post a Comment