A web service in general is a way of exposing the properties and methods through the Internet In other words, it's an URL-addressable resource that programmatically returns information to clients who want to use it. A web service is based on XML standards and has been implemented by different vendors like IBM, Sun Microsystems, CapeClear etc. Currently there is no official body, such as the W3C who have under taken the job of defining this fast evolving technology.
Web services have been foreseen as the future of computing over the web and are more pronounced in the .NET framework owing to its ease in development as well as consumption with or even without VisualStudio.NET. A webservice works on Simple Object Access Protocol (SOAP). Every call to the webmethod from the client's machine is sent in the form of a SOAP envelope and result from the server is sent back in SOAP containing the result.
The facility of language interoperability that .NET offers within its Common Language Runtime (CLR) offers a new dimension to using web services. Owing to these attractive features, .NET is predicted to take command of the client side computing market in the years to come. We can for sure get a feel on the nature of computing where you could develop and use applications in languages of your choice, at least in .NET environment.
In this article I plan to elaborate more on this aspect by
- Developing a simple web service in a normal text editor in C#.
- Consuming the web service described above through a console application written in VB.NET.
Although the application might seem complicated, it is fairly simple to achieve this objective. For the sake of better understanding, I have illustrated simple and straightforward examples.
Let's march in to out first step of our objective.
Creating a simple Web service in C#
The webservice application provides a Web Method called Add, which takes in two integers as parameters and returns their sum as integer. The following code is typed in a simple text editor.
<%@WebService Language="c#" class ="sumThis"%>
using System;
using System.Web.Services;
public class sumThis:WebService
{
[WebMethod]
public int Add(int a,int b)
{
int sum;
sum=a+b;
return sum;
}
}
Note: MSDN documents imply that although language interoperability is supported within the .NET platform, it is advisable to use attributes like the ones described below to ensure type compliancy detection at compile time. In other words, these attributes help identify the types that are not recognized by the CTS at compile time. These attributes need to be included in the program prior to declaration of the class in the program.
//optional attributes to ensure type compliancy
// Assembly marked as compliant.
[assembly: CLSCompliantAttribute(true)]
// Class marked as compliant.
[CLSCompliantAttribute(true)]
Few pointers that one must pay attention to while developing a web service are:
- The file must be saved as filename.asmx. The file can be checked for its proper syntax and its construct by opening it in a web browser.
- It is not necessary to compile the web service (.asmx) file.
- In case of developing a webservice in VB.NET one must use the construct <WebMethod()> instead of the regular construct [WebMethod] used in C#.




Join the conversation! Your thoughts help the community grow.