Recently, because of the Web module in the project group, start learning the .NET platform, discovering that using a web service in the .NET platform is still very simple. The following is a simple example of creating a web service under the .NET platform. First created with a Visul Studio .Net C # project Asp.Net Web service program, the source code is as follows: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Web; using System.Web.Services;
A summary description of Namespace Author {///
#Region component designer generated code // Web service designer essential private icontainer components = null; ///
///
// Web Service Sample // HelloWorld () Sample Service Returns Hello World // To generate, cancel the following list, then save and generate items // To test this web service, press F5 button
// [WebMethod] // public string helloworld () // {// return "Hello World"; //}
}} These code are automatically generated by the system. From here, it can be seen that the ordinary approach has become a web method after adding the WebMethod property. The following is a method of accessing the SQL Server database. The code is as follows: [WebMethod] Public DataSet DataVisit (String ID) {string myselectQuery = "SELECT AU_ID, AU_FNAME, AU_LNAME FROM AUTHORE AU_ID! = '" ID " "; string myConn = @" server = localhost; uid = sa; database = pubs "; SqlConnection myConnection = new SqlConnection (myConn); SqlCommand myCmd = new SqlCommand (mySelectQuery, myConnection); myConnection.Open (); SqlDataAdapter adapter = new SqldataAdapter (); adapter.selectcommand = mycmd; dataset myds = new dataset (); adapter.fill (myds, "author_name"); myconnection.close (); returnnection;} This created a web service, in Web This service can be used by adding "Web Reference". Use this method to easily create a three-layer mode.