C # webservice writing, publishing, and calling

Source: Internet
Author: User

Use the tool VS2010 to generate a project 1. Generate a webservice project: Create an ASP. NET empty WEB application. 2. Create a new "WEB Service" in the ASP. NET empty web application ". To complete the above content project structure, the main operation below is in webservice1.asmx. cs file, which contains several services, two simple services, two query database services; using System. collections. generic; using System. linq; using System. web; using System. web. services; using System. data. sqlClient; using System. data; using MySql. data; using MySql. data. mySqlClient; namespace webservice {// <summary> // summary of WebService1 /// </summary> [WebService (Namespace = "http://tempuri.or G/")] [WebServiceBinding (ConformsTo = WsiProfiles. basicProfile1_1)] [System. componentModel. toolboxItem (false)] // to allow ASP. net ajax calls this Web service from the script. Please cancel the comments to the downstream. // [System. web. script. services. scriptService] public class WebService1: System. web. services. webService {[WebMethod] public string HelloWorld () {return "Hello World";} [WebMethod] public int GetSum (int a, int B) {return a + B ;} [WebMethod] public DataSet query () {DataSet ds = new DataSet (); string connstring = "Database = test; Data Source = localhost; User Id = root; Password = root "; mySqlConnection mycn = new MySqlConnection (connstring); mycn. open (); MySqlDataAdapter mda = new MySqlDataAdapter ("select * from stock_data", mycn); mda. fill (ds, "stock_data"); return ds;} [WebMethod] public DataSet goldprice () {DataSet ds = new DataSet (); string connstring = "Database = test; data Source = localhost; User Id = root; Password = root "; MySqlConnection mycn = new MySqlConnection (connstring); mycn. open (); MySqlDataAdapter mda = new MySqlDataAdapter ("select * from goldprice", mycn); mda. fill (ds, "stock_data"); return ds ;}}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.