Khi bạn sử dụng các dịch vụ Web trong logic của bạn, SOAP được sử dụng như các giao thức mặc định. Mặc dù có vẻ nhiều hơn một chút cồng kềnh hơn so với các tùy chọn khác, đó là cơ chế duy nhất mà làm cho nó có thể sử dụng các phương pháp Web trực tiếp, một cách linh hoạt, và liền mạch từ bên trong mã. | Web Services When you use Web services within your logic SOAP is used as the default protocol. Although it seems a little more bulky than the other options it s the only mechanism that makes it possible to use Web methods directly in a flexible manner and seamlessly from within the code. Building an Web Service Let s take a more detailed look at putting a Web service together. We ll also begin to explore the possible uses for Web services. You can define a Web service by simply writing a few lines of code and placing them inside a file with a .asmx extension. This extension tells Web Matrix that a Web service is being defined. You can create a Web service just like a standard page using Web Matrix as we did earlier in the chapter or any text editor. A Web service must contain four essential parts Processing directive. Namespaces. Public class. Web methods. Let s look at each of these in turn. Processing Directive Within the empty ASMX file the required file type for an Web service page you must let the Web server know that you re creating a Web service. To do this enter a directive at the top of your page with the following syntax in fact Web Matrix creates this automatically based on the information submitted in the startup dialog @ WebService Language language Class classname This statement appears at the top of an source file to tell the .NET Framework about any settings or constraints that should be applied to whatever object is generated from the file. In this case the directive tells the compiler the language in which the Web service is written and the name of the class in which it is defined. This class might reside in the same file or within a separate file which must be in the bin directory immediately beneath the Web application root in which the Web service lives . Namespaces You can make use of other file s logic within your ASMX page by specifying appropriate namespaces. In this case you can use the C using .