tailieunhanh - Mastering Microsoft Visual Basic 2010 phần 10

chúng tôi tương tác với cơ sở dữ liệu bằng cách sử dụng bốn loại lệnh khác nhau: một để chọn dữ liệu và tải chúng vào máy tính của khách hàng với sự giúp đỡ của một đối tượng DataReader (một đối tượng Command với các câu lệnh SELECT) và ba trình cơ sở dữ liệu các hàng mới | BUILDING AND USING WCF SERVICES 913 of the service s methods instead of using the collections as its data source the service will contact a database. In between sessions you can persist the collections to an XML file as discussed in Chapter 13 XML in Modern Programming. Start a fresh instance of Visual Studio and select File New New Project. Click WCF in the Installed Templates pane and in the pane with the matching project types select WCF Service Library. Name the new project WCFProducts and click OK to create the project. The new project that Visual Studio will create for you contains two files the class which is an interface that contains the signatures of the service methods and the class which contains the implementation of the methods. The methods are some extremely trivial sample methods and you can delete them right away. The first step is the design of a class that represents the entities our service knows about. Obviously we need a Product and a Category class and I have nested the Category class within the Product class. Both classes contain just a few properties to identify products and categories. Add the Product class to the WCF project and insert in it the code of Listing . Listing The class DataContract Public Class Product DataMember Public ProductID As Integer DataMember Public ProductName As String DataMember Public ProductPrice As Decimal DataMember Public ProductCategoryID As Integer Public Overrides Function ToString As String Return ProductName ProductID End Function DataContract Public Class Category DataMember Public CategoryID As Integer DataMember Public CategoryName As String Public Overrides Function ToString As String Return CategoryName End Function End Class End Class This is a very simple class that describes products and categories if you ignore the decorations of the various members. The entire class is marked with the DataContract attribute which tells the compiler

TỪ KHÓA LIÊN QUAN