What is Webservices and how it works
This article gives an introductionto webservices and explains how it works.
Webservices is mainly used for accessing methods in a remote server. and it is based on SOAP protocol for communicating between the server and client.
In a remote server there will be some public webmethods.
Similar to the webservice in the remote server, there will proxy client file in the clinet site.
Whenever the request is made to the server for a method, proxy client will be checking all the inputs are correct ie the arguments are right and the argument types are right ...etc.
If any input is wrong, the proxy client will be intimating the error to the client.
If the input is correct, proxy client will convert it into xml format and send to the server through SOAP protocol.
In the server side, these input are taken and process the requested methods and send the results to the proxy client in the same format XML through SOAP protocole.
In the proxy client, it will parse the XML content and extract the result and send to the client.
This how basically Webservices are working.
The extension for webservice is asmx.
The following example shows a very simple .asmx file.
<%@ WebService Language="C#" Class="HelloWorld" %>
using System;
using System.Web.Services;
public class HelloWorld : WebService {
[WebMethod] public String SayHello(string name) {
return "Hello " + name;
}
}
We can make the proxy client through the command wsdl
eg :- WSDL http://someDomain.com/someFolder/Hello.asmx?WSDL to create a proxy class called Hello.cs.
Compile this proxy client file and put it in the bin folder of your application and add references to it.
In the client file we can access the Webservice webmethods through the following way
Hello hl=new Hello();
Response.Write(hl.SayHello("SIju"));
The out put will be "Hello Siju".
I hope you unserstand how to create webservice and how it is executing.
Hi to all,
How we can use a WebService which is in another server? I have added a reference using "Add Web Reference .." through solution explorer and added successfully a web reference in my client machine and now usinig its class. The code i have used for that ...
WebReference.Service1 s = new WebReference.Service1();
s.ShowDetail();
It works fine .. but i get from some articles, that it is must to creat a proxy class to use a web service. Here i added only a web reference not adding much more, not creating a proxy class and it works fine too. Is it a second method to use a web service..
Let me clear about how is it working.
Thanks