using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Diagnostics; using System.Web; using System.Web.Services; using System.Configuration; namespace Ch2 { /**////<summary> /// Summary description for SearchTitles. ///</summary> publicclass SearchTitles : System.Web.Services.WebService { public SearchTitles() { //CODEGEN: This call is required by the ASP.NET Web Services Designer InitializeComponent(); } private System.Data.SqlClient.SqlConnection sqlConnection1; Component Designer generated code#region Component Designer generated code //Required by the Web Services Designer private IContainer components =null; /**////<summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. ///</summary> privatevoid InitializeComponent() { this.sqlConnection1 =new System.Data.SqlClient.SqlConnection(); // // sqlConnection1 // this.sqlConnection1.ConnectionString ="workstation id=\"gw\";packet size=4096;user id=sa;data source=\"gw\";pe"+ "rsist security info=True;initial catalog=pubs;password="; } /**////<summary> /// Clean up any resources being used. ///</summary> protectedoverridevoid Dispose( bool disposing ) { if(disposing && components !=null) { components.Dispose(); } base.Dispose(disposing); } #endregion // WEB SERVICE EXAMPLE // The HelloWorld() example service returns the string Hello World // To build, uncomment the following lines then save and build the project // To test this web service, press F5 [WebMethod] publicstring doSearch(string keyword) { //SqlConnection cn=new SqlConnection(ConfigurationSettings.AppSettings["pubs"]); SqlDataAdapter da=new SqlDataAdapter("select top 20 title_id,title from titles where title like @title",sqlConnection1); da.SelectCommand.Parameters.Add(new SqlParameter("@title","%"+keyword+"%")); DataSet ds=new DataSet(); da.Fill(ds); return ds.GetXml(); } } }