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

Mặc dù trong nhiều trường hợp, bạn sẽ muốn làm việc với XML sống hoặc JSON trở về từ một dịch vụ WDS, nó được dễ dàng hơn để làm việc với proxy lớp học tạo ra. Các lớp học proxy tạo ra làm cho nó rất dễ dàng để thực hiện CRUD đơn giản và hoạt động truy vấn. Tất nhiên, đằng sau hậu trường mà họ sử dụng HTTP. | CHAPTER 9 WCF DATA SERVICES WDS Proxy Classes Although in many cases you will want to work with the raw XML or JSON returned from an WDS service it is easier to work with generated proxy classes. The generated proxy classes make it very easy to perform simple CRUD and query operations. Of course behind the scenes they use HTTP. Retrieving Items with Proxy Classes We will create an application to iterate through the Order objects using LINQ and the DataServiceContext class. 1. Add a new console application to the solution called . 2. Right click the References folder. 3. Select Add Service Reference to add the URL your WDS is set up at for example http localhost Chapter9 . 4. Select the BookEntities node in the Services box. 5. Enter the namespace MovieService. 6. Click OK. Visual Studio will generate classes representing the entities in our console application. Figure 9-9. Adding service reference to WDS service 218 CHAPTER 9 WCF DATA SERVICES 7. Open and add the following using statement using 8. Enter the following code to iterate through a list of Orders printing the first name to the output window static void Main string args DataServiceContext ctx new DataServiceContext new Uri http localhost Chapter9 var Orders new Uri Orders foreach Order in Orders 9. Press F5 to run the application and you should see a list of first names from the Orders table printed out. Adding a New Item with Proxy Classes To create a new item using WCF Data Services is very easy and just requires using the DataServiceContext s AddObject and SaveChanges methods static void Main string args DataServiceContext ctx new DataServiceContext new Uri http localhost Chapter9 NewFilm new Pulp Fiction

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.