Working with Web Services Using ASP.NET
page 6 of 11
by SANJIT SIL
Feedback
Average Rating: 
Views (Total / Last 10 Days): 58569/ 154

Building a Web Service

Building a Web Service with Visual Studio.Net involves creating a new Web Services project and adding methods and properties to a Web Services class form (i.e. an .asmx file).  This section builds a Web Service with Visual Studio.Net.  Followings are the steps in short to create an .asmx file.

1.      Start Visual Studio .NET

2.      Select New Project

3.      Select Visual C# Project as Project Type and Asp.Net Web Service as Template

A solution will be generated.  In solution explorer there will be an asmx file.

The following code we should write in .asmx file as specified in Listing 4.

Listing 4

[WebMethod]
  public string Add(int a, int b)
  {
    return Convert.ToString(a + b);
  }
 
[WebMethod]
  public DataSet Populate(string con, string sql)
  {
    DataSet DS=new DataSet();
    SqlConnection conn=new SqlConnection(con);
    SqlDataAdapter DA=new SqlDataAdapter(sql, conn);
    DA.Fill(DS);
    return DS;
  }

In the above code there are two methods in Web Service.  These methods are known as the WebMethods.  The Add WebMethod returns the sum of two integer value as string.  Populate web method takes two string type arguments, one for connection string and the other for sql query, and returns a DataSet object.


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-10-16 1:03:35 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search