Pro Entity Framework 4 0 Depositfiles_7
Số trang: 26
Loại file: pdf
Dung lượng: 1.55 MB
Lượt xem: 7
Lượt tải: 0
Xem trước 3 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tham khảo tài liệu pro entity framework 4 0 depositfiles_7, công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Pro Entity Framework 4 0 Depositfiles_7 CHAPTER 11 ■ N-TIER DEVELOPMENT WITH WCF DATA SERVICESFigure 11-6. The AWService WCF Service When the ADO.NET Data Service is added to our project, the associated .cs file will automatically bedisplayed in the IDE. Figure 11-7 shows that file, and what the ADO.NET Data Service template hasgenerated for us. The result is basically the beginning of our data service.Figure 11-7. Data Service shell As you can see in Figure 11-7, the template also generates some instructions for us, which provideus some direction as to what we need to do next. The first thing we need to do is wire up our data serviceto our data model so that the service knows where to get its data. We know where to do this because, as 193CHAPTER 11 ■ N-TIER DEVELOPMENT WITH WCF DATA SERVICES you can see in the highlighted code in Figure 11-7, the code tells us where. Thus, replace the code comment with the name of the AdventureWorksEntities (see the note a few pages back regarding this value). When you have made the change, the public class line of code will look like the following: public class AWService : DataService< AdventureWorksEntities > Wiring up our data service to the model is as simple as that. Believe it or not, we are ready to test our service. Testing the WCF Data Service Testing our WCF Data Service provides us not only the chance to see if our little application works, but also the opportunity to explore some of the WCF Data Service functionality and the interaction between EF and the WCF Data Service. You will also see why we built this project in an ASP.NET Web Application. Press Ctrl + F5 to compile and run the project. When the project runs, the web browser will open and display what you see in Figure 11-8. Figure 11-8. Initial test results On the surface the results in Figure 11-8 really don’t tell us much, except for the fact that we have a REST-based (REpresentational State Transfer) service running on top of our database using the Entity Framework. That’s still very cool, though. Yet, our output in the browser isn’t showing us what we want. What we really want to see is data from the database. We don’t see data because, by default, the WCF.NET Data Service is secured. The WCF Data Service needs to be told explicitly which data you want to see. The instructions in the code tell us this, as you can see in Figure 11-7, in the TODO comment. Some examples are even provided in the comments to help us out. But the comment is there as a reminder. We still have to do some work. Let’s choose to not restrict anything in our example. Instead, we’ll unlock all the entities. We do that by adding the highlighted code below to the InitializeService method:194 CHAPTER 11 ■ N-TIER DEVELOPMENT WITH WCF DATA SERVICESpublic static void InitializeService(DataServiceConfiguration config){ // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc. // Examples: // config.SetEntitySetAccessRule(MyEntityset, EntitySetRights.AllRead); // config.SetServiceOperationAccessRule(MyServiceOperation, ServiceOperationRights.All); config.SetEntitySetAccessRule(*, EntitySetRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;} The highlighted code sets the permissions for the specified entity sets in our model. TheSetEntitySetAccessRule method takes two parameters. The first parameter is the entity we want to setpermissions for, and the second parameter is the access rights to be granted to this resource (entity). By specifying the value of * in the first parameter, we are specifying that we want to set permissionsfor all entity sets. The second parameter takes the EntitySetRights enumeration, which contains thefollowing members: None: Denies all rights to data access • ReadSingle: Authorizes read rights to single items • ReadMultiple: Authorizes read rights to sets of data • WriteAppend: Authorizes create rights on data items in data sets • WriteReplace: Provides rights to replace data • WriteDelete: Authorizes deletes on data items from data sets • WriteMerge: Authorizes rights to merge data • AllRead: Authorizes read data rights • AllWrite: Authorizes write data rights • All: Authorizes read, create, update, and delete rights on data ...
Nội dung trích xuất từ tài liệu:
Pro Entity Framework 4 0 Depositfiles_7 CHAPTER 11 ■ N-TIER DEVELOPMENT WITH WCF DATA SERVICESFigure 11-6. The AWService WCF Service When the ADO.NET Data Service is added to our project, the associated .cs file will automatically bedisplayed in the IDE. Figure 11-7 shows that file, and what the ADO.NET Data Service template hasgenerated for us. The result is basically the beginning of our data service.Figure 11-7. Data Service shell As you can see in Figure 11-7, the template also generates some instructions for us, which provideus some direction as to what we need to do next. The first thing we need to do is wire up our data serviceto our data model so that the service knows where to get its data. We know where to do this because, as 193CHAPTER 11 ■ N-TIER DEVELOPMENT WITH WCF DATA SERVICES you can see in the highlighted code in Figure 11-7, the code tells us where. Thus, replace the code comment with the name of the AdventureWorksEntities (see the note a few pages back regarding this value). When you have made the change, the public class line of code will look like the following: public class AWService : DataService< AdventureWorksEntities > Wiring up our data service to the model is as simple as that. Believe it or not, we are ready to test our service. Testing the WCF Data Service Testing our WCF Data Service provides us not only the chance to see if our little application works, but also the opportunity to explore some of the WCF Data Service functionality and the interaction between EF and the WCF Data Service. You will also see why we built this project in an ASP.NET Web Application. Press Ctrl + F5 to compile and run the project. When the project runs, the web browser will open and display what you see in Figure 11-8. Figure 11-8. Initial test results On the surface the results in Figure 11-8 really don’t tell us much, except for the fact that we have a REST-based (REpresentational State Transfer) service running on top of our database using the Entity Framework. That’s still very cool, though. Yet, our output in the browser isn’t showing us what we want. What we really want to see is data from the database. We don’t see data because, by default, the WCF.NET Data Service is secured. The WCF Data Service needs to be told explicitly which data you want to see. The instructions in the code tell us this, as you can see in Figure 11-7, in the TODO comment. Some examples are even provided in the comments to help us out. But the comment is there as a reminder. We still have to do some work. Let’s choose to not restrict anything in our example. Instead, we’ll unlock all the entities. We do that by adding the highlighted code below to the InitializeService method:194 CHAPTER 11 ■ N-TIER DEVELOPMENT WITH WCF DATA SERVICESpublic static void InitializeService(DataServiceConfiguration config){ // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc. // Examples: // config.SetEntitySetAccessRule(MyEntityset, EntitySetRights.AllRead); // config.SetServiceOperationAccessRule(MyServiceOperation, ServiceOperationRights.All); config.SetEntitySetAccessRule(*, EntitySetRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;} The highlighted code sets the permissions for the specified entity sets in our model. TheSetEntitySetAccessRule method takes two parameters. The first parameter is the entity we want to setpermissions for, and the second parameter is the access rights to be granted to this resource (entity). By specifying the value of * in the first parameter, we are specifying that we want to set permissionsfor all entity sets. The second parameter takes the EntitySetRights enumeration, which contains thefollowing members: None: Denies all rights to data access • ReadSingle: Authorizes read rights to single items • ReadMultiple: Authorizes read rights to sets of data • WriteAppend: Authorizes create rights on data items in data sets • WriteReplace: Provides rights to replace data • WriteDelete: Authorizes deletes on data items from data sets • WriteMerge: Authorizes rights to merge data • AllRead: Authorizes read data rights • AllWrite: Authorizes write data rights • All: Authorizes read, create, update, and delete rights on data ...
Tìm kiếm theo từ khóa liên quan:
thủ thuật máy tính tài liệu công nghệ thông tin lập trình máy tính mẹo máy tính cài đặt máy tínhGợi ý tài liệu liên quan:
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 318 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 305 0 0 -
Thêm chức năng hữu dụng cho menu chuột phải trên Windows
4 trang 290 0 0 -
70 trang 251 1 0
-
Bài giảng Tin học lớp 11 bài 1: Giới thiệu ngôn ngữ lập trình C#
15 trang 238 0 0 -
Tổng hợp lỗi Win 8 và cách sửa
3 trang 234 0 0 -
Sửa lỗi các chức năng quan trọng của Win với ReEnable 2.0 Portable Edition
5 trang 214 0 0 -
Giáo trình Bảo trì hệ thống và cài đặt phần mềm
68 trang 208 0 0 -
Tổng hợp 30 lỗi thương gặp cho những bạn mới sử dụng máy tính
9 trang 205 0 0 -
Phần III: Xử lý sự cố Màn hình xanh
3 trang 204 0 0