Thursday, December 11, 2008

The world of Web services!

Today i wanted to understand what Web services are exactly..
It appears that it is basically a module software that can be accessed by many diff applications over the net. Eg: Add() - this can be written as a web service & then accessed by diff applns like CALC or MATHWORK.
It uses HTTP for transferring the data from source to dest over the net.
Eg: Appln1 has a function which is a web service. Once this is published on the net, appln2 can access this func. so basically appln1 & appln2 is accessing each other.


SOAP(simple object access protocol) - This is d COMMUNICATION PROTOCOL used for accessing web service.
Web Service -----soap-------> Application 1
soap = xml + http (Data exchanged as XML over HTTP)


WSDL(web services descript lang)
Used 2 describe & locate web sertvices.


UDDI(Universal Description, Discovery and Integration)
You can register your WS here.


A code example : Very Important:
CREATING A WEB SERVICE. (Amen!! ;) )
---------------------------------------------
(1) Include namespace system.web.services
(2) Inherit fm WebService base class
(3) [WebMethod] attribute before the fn u wanna expose
******************************************
using System.Web.Services

[WebService(Namespace=http://localhost/MyWebServices/)]
public class FirstService : WebService
{
[WebMethod]
public int Add(int a, int b)
{ return a + b; }

[WebMethod]
public String SayHello()
{ return "Hello World"; }
}
*****************************************

PUBLISHING A WEB SERVICE-Create a virtual directory in IIS. Place ur .ASMX file there. Open the .ASMX file fm d browser.

CREATE A PROXY FOR THE WEB SERVICE USING WSDL UTILITY & PLACE IT IN /BIN DIRECTORY- (One for each web service) - Apparently VS.NET does this job for us when we reference the wotever..nt sure..hafta check..

C:/>WSDL http://localhost/mywebservice.asmx - This generates the mywebservice.cs file.

C:/>CSC mywebservice.cs - Generates mywebservice.dll (Proxy)

For sample example pls refer C:\My WorkArea\WEB SERVICE on local system.

Websites that helped:

www.w3schools.com

http://www.codeguru.com/csharp/csharp/cs_webservices/tutorials/article.php/c5477