Home > Articles > Mobile Application Development & Programming

  • Print
  • + Share This
From the author of Adding a Reference to the LightSwitch OData Service

Adding a Reference to the LightSwitch OData Service

In Solution Explorer, right-click the project name and select Add Service Reference. This command should be familiar, since you used it in Part 3 of this article series, and probably in other situations of your own. In the Add Service Reference dialog, you'll have to specify the URL for the desired data source, in this case the LightSwitch intrinsic data. The URL has the following form:

http://servername/applicationname/ApplicationData.svc

In the current example, the server name is the local Internet Information Services name (LocalHost) and the application name is ExposingOData, so the URL is as follows:

http://localhost/ExposingOData/ApplicationData.svc

However, it's a good idea to specify the IP address rather than the name for the server. In fact, depending on the system configuration (for example, when working with the Windows Phone 8 Emulator), providing the server name wouldn't always work, whereas supplying the IP address would.

When you click Go, Visual Studio 2012 will ask you to enter credentials to download the service information (see Figure 3). Here you have to enter credentials for the LightSwitch application administrator that you specified in the Publish Wizard when publishing the application to the web server.

Figure 3 Entering administrator credentials to access the OData service.

At this point, Visual Studio displays the list of entity sets exposed by the OData service, in this case Customers and Orders. The default service namespace is ServiceReference1, but you can change it to OrdersServiceReference for consistency. Figure 4 shows how the dialog looks.

Figure 4 Visual Studio shows entity sets available in the OData service.

Discovering the OData service on the network and displaying the list of available entity sets has been possible to Visual Studio due to the developer tools that I asked you to install at the beginning of this article. When you click OK in the Add Service Reference dialog, 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. Now you have also completed the steps required to add a reference to LightSwitch's OData service.

  • + Share This
  • 🔖 Save To Your Account