Partager via


Accessing the Service from a Web Browser (WCF Data Services Quickstart)

Important

WCF Data Services has been deprecated and will no longer be available for download from the Microsoft Download Center. WCF Data Services supported earlier versions of the Microsoft OData (V1-V3) protocol only and has not been under active development. OData V1-V3 has been superseded by OData V4, which is an industry standard published by OASIS and ratified by ISO. OData V4 is supported through the OData V4 compliant core libraries available at Microsoft.OData.Core. Support documentation is available at OData.Net, and the OData V4 service libraries are available at Microsoft.AspNetCore.OData.

RESTier is the successor to WCF Data Services. RESTier helps you bootstrap a standardized, queryable, HTTP-based REST interface in minutes. Like WCF Data Services before it, Restier provides simple and straightforward ways to shape queries and intercept submissions before and after they hit the database. And like Web API + OData, you still have the flexibility to add your own custom queries and actions with techniques you're already familiar with.

This is the second task of the WCF Data Services quickstart. In this task, you start the WCF Data Services from Visual Studio and optionally disable feed reading in the Web browser. You then retrieve the service definition document as well as access data service resources by submitting HTTP GET requests through a Web browser to the exposed resources.

Note

By default, Visual Studio auto-assigns a port number to the localhost URI on your computer. This task uses the port number 12345 in the URI examples. For more information about how to set a specific port number in your Visual Studio project see Creating the Data Service.

To request the default service document by using Internet Explorer

  1. In Internet Explorer, from the Tools menu, select Internet Options, click the Content tab, click Settings, and clear Turn on feed viewing.

    This makes sure that feed reading is disabled. If you do not disable this functionality, then the Web browser will treat the returned AtomPub encoded document as an XML feed instead of displaying the raw XML data.

    Note

    If your browser cannot display the feed as raw XML data, you should still be able to view the feed as the source code for the page.

  2. In Visual Studio, press the F5 key to start debugging the application.

  3. Open a Web browser on the local computer. In the address bar, enter the following URI:

    http://localhost:12345/northwind.svc
    

    This returns the default service document, which contains a list of entity sets that are exposed by this data service.

To access entity set resources from a Web browser

  1. In the address bar of your Web browser, enter the following URI:

    http://localhost:12345/northwind.svc/Customers
    

    This returns a set of all customers in the Northwind sample database.

  2. In the address bar of your Web browser, enter the following URI:

    http://localhost:12345/northwind.svc/Customers('ALFKI')
    

    This returns an entity instance for the specific customer, ALFKI.

  3. In the address bar of your Web browser, enter the following URI:

    http://localhost:12345/northwind.svc/Customers('ALFKI')/Orders
    

    This traverses the relationship between customers and orders to return a set of all orders for the specific customer ALFKI.

  4. In the address bar of your Web browser, enter the following URI:

    http://localhost:12345/northwind.svc/Customers('ALFKI')/Orders?$filter=OrderID eq 10643
    

    This filters orders that belong to the specific customer ALFKI so that only a specific order is returned based on the supplied OrderID value.

Next Steps

You have successfully accessed the WCF Data Services from a Web browser, with the browser issuing HTTP GET requests to specified resources. A Web browser provides an easy way to experiment with the addressing syntax of requests and view the results. However, a production data service is not generally accessed by this method. Typically, applications interact with the data service through application code or scripting languages. Next, you will create a client application that uses client libraries to access data service resources as if they were common language runtime (CLR) objects:

See also