tailieunhanh - Lập trình .net 4.0 và visual studio 2010 part 31

WCF dịch vụ dữ liệu (trước đây "Astoria" và Data Services) cho phép dữ liệu được sửa đổi và tiếp xúc qua một giao diện HTTP RESTful. Dữ liệu WCF Services (WDS) chứa một ngôn ngữ truy vấn phong phú và có thể được truy cập dễ dàng với tự động tạo ra các lớp proxy hoặc crafting nguyên yêu cầu HTTP. | CHAPTER 9 WCF Data Services Availability .NET limited functionality onwards WCF Data Services previously Astoria and Data Services allows data to be modified and exposed over an HTTP RESTful interface. WCF Data Services WDS contains a rich query language and can be accessed easily with automatically generated proxy classes or crafting raw HTTP requests. WCF Data Services supports returning data in a number of popular data formats such as XML AtomPub and JSON and is potentially very useful for integration scenarios and applications that don t maintain a direct connection to the database such as Silverlight. NOTE During the course of writing this chapter Microsoft changed the name of Data Services to WCF Data Services. However the VS template names have not changed yet so the examples in this chapter use the Data Services template names. Hello WCF Data Services Before we can get started with WDS we are going to need some data to play with. If you haven t already done so please refer to the introduction and set up the example database. In this chapter we will be using SQL Server 2008 but don t think that you are limited to using just SQL Server since WDS will work with anything supported by Entity Framework Chapter 8 . To expose our data we have to perform four steps 1. Create Entity Framework classes for the data we want to expose 2. Create a host application for the WDS service 3. Create the WDS service 4. Configure access rules for the service Let s get started. Open Visual Studio and create a new web site change the Web location dropdown to HTTP and enter the location as http localhost Chapter9 . 207 CHAPTER 9 WCF DATA SERVICES WARNING Hosting WCF Data Services in IIS on one machine gave me HTTP 500 whenever I tried to query data. I never got to the bottom of why this was so all I can say is if you experience this try working with the local web server instead. Entity Framework WDS needs to know how the data we want to