Creating a Sample Application
In Visual Studio 2010, create a Windows Phone project. I'm using Visual Basic as the programming language for this example, but the steps are the same for Visual C#:
- Select the Windows Phone Application template and specify MobileOrdersClient as the project name, as shown in Figure 4.
- When you click OK, Visual Studio will ask which version of Windows Phone the project must target; select Windows Phone 7.1.
- After creating the project, add a reference to the OData service by selecting Project > Add Service Reference.
- In the Add Service Reference dialog, specify the URL of the service for the desired data source. (In this case, the service reference will point to the LightSwitch intrinsic data.) Click Go.
- Visual Studio requests your administrator credentials to download the service information. Enter the username and password for the LightSwitch application administrator that you specified in the Publish Application Wizard when publishing the application to the web server (see Figure 5).
- Visual Studio displays the list of entity sets exposed by the OData service, in this case Customers and Orders (see Figure 6). The service namespace is ServiceReference1. Change it to OrdersServiceReference and click OK.
The selected project template is the most basic; it doesn't include sample data or a prebuilt user interface, so we can add our logic without wasting time having to remove or change unused objects.
Figure 4 Creating a Windows Phone project.
Remember that Windows Phone 7.1 is the version of the SDK, but it actually targets version 7.5 of the operating system (also known as Mango). In other words, if you select the Windows Phone 7.1 developer tools, your app will run on Windows Phone 7.5.
Figure 5 Specifying administrator credentials for connecting to the OData service.
Visual Studio generates a proxy class required for connecting to the service in .NET code, as well as two business classes representing customers and orders.
There's nothing else to do to reference an OData service. The rest of the required tasks will be performed later in code (such as connecting to the service and working with data).
Figure 6 Visual Studio shows entity sets available in the OData service.