CSharp web services

Posted by

Webservices with CSharp provide us the facility to talk to other platforms easily with messages exchanging protocols such as HTTP, XML, XSD, SOAP, and WSDL
What Webservices actually do is to convert the data (oracle,sql server,mysql) into xml files and transfer it to the requesting client/server.
It is a blessing to visualize the data transfer between windows and Unix machines with the aid of Webservices.

Advantages of using Webservices

1. Data transfer between different platforms such as Windows and Unix

2. The data transfer algorithms can be written in any programming language. This is called interoperability

3.These services are driven by the most reliable and latest protocols such as

Extensible Markup Language (XML)
Hypertext Transfer Protocol (HTTP)
Universal Description, Discovery, and Integration (UDDI)
Web Services Description Language (WSDL).

What is SOAP and its link with webservices

SOAP, originally defined as Simple Object Access Protocol, is a protocol specification for exchanging structured information in the implementation of web services in computer networks. It relies on XML Information Set for its message format, and usually relies on other application layer protocols, most notably Hypertext Transfer Protocol (HTTP) or Simple Mail Transfer Protocol (SMTP), for message negotiation and transmission.

Simple Webservice program in C#

1.Open up your Visual Studio IDE.
2.On the file menu, click new and then project . Select Visual C# Projects, select ASP.NET Web Service under the existing Templates. Name the service myService.
3.Change the name of created service from Service1.asmx to myService.asmx. Click here and open code view.
4.Make method(s) with the attribute WebMethod. It is necessary to do this to operate over webservice(s)

The program

On myService class, type the following code:

public int AdditionMethod(int i, int j)
return(i + j);

using System.Data.SqlClient ;

public DataSet FetchRecords()

SqlConnection con = new SqlConnection();

con.ConnectionString = “data source=MSSQLEXPRESS;initial catalog=Company;integrated security=SSPI”;

string query =”select * from tbl_Employees “;
SqlDataAdapter da = new SqlDataAdapter(query,con);
DataSet ds = new DataSet();

Run these methods and enjoy your day 🙂

Facebook Comments

Syed Adeel Ahmed
Analyst, Programmer, Educationist and Blogger at Technofranchise
Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.
Syed Adeel Ahmed on FacebookSyed Adeel Ahmed on GoogleSyed Adeel Ahmed on InstagramSyed Adeel Ahmed on Twitter