The most obvious use of XML Web Services is universal data access. With it, you can access your company's database by many clients on the Internet, or dynamically import it to a third-party Web site, you can even allow your business partner's Web Services to query. The following explains how to create a simple Web service to display your database content to Internet Explorer, third-party Web Services, and custom C # and VB. NET clients.
Partners, customers, and employees have a wealth of experience in using data designed for multiple devices. No matter how your current database is organized, to ensure universality, web Services returns XML data to the client. For example, if a Logistics Company (your partner) wants to deliver your goods to your customers, when the delivery arrives at the customer's door, his PDA displays the information about the change of the departure address. At this time, the freight car easily delivers the information to other places, because your customer has changed his address in the database, this change is automatically updated in your partner's system.
Next, write your own ASP. NET database Web Services. First, check your database to see if it can easily output data in XML format and whether ADO. NET can be read and dynamically converted. In some cases, you may need to convert the current database to meet this requirement. If your database access code becomes complex and affects scalability, we recommend that you convert the database.
For simplicity, we assume that the database in the example has only one "Products" table. Of course, your database may have many tables, or your Web Services may need to access more than one database.
Now we can start writing code. Open Visual Studio. NET and create a C # ASP. NET Web Services project under the DataBaseWebService directory,
Right-click Service1.asmx and rename Service1.asmx to DataBaseWebService. asmx. This file will contain WebMethods that obtain data from the database. Then, right-click and select "view code" to switch to the Code view and change it to the DataBaseWebService class and constructor name.
First, reference the. NET Class Library: using System. Data. SqlClient;