Web Services is service which is available over the web. A Web Service
is used to implement the specific functionality to Execute the business
logic codes of the application . This technologies allowed to
developer to create a specific component once (make only logic code) so
that they can share it across the multiple application by multiple
developers. Before the Web Services , we were using two technology which
are given below:-
- Component object model (COM)
- Distributed Component object model (DCOM)
This
technology is helpful to use one application to another
application.However ,there were some fundamental difficulties in using
these components. One such difficulty was that these components needed
to be physically distributed and Explicitly registered on each client machine.
Today,Web
Services overcome these difficulties as they can be shared (distributed)
among multiple website without the need to install them on each
individual client machines.
There are some advantages of web services over COM and DCOM Technologies.
- Web Services are very simple in use.
- Web Services do not carry any state information,so that multiple request can be processed simultaneously.
- Web Services are enforcing trusted connection between the server and the client.
- Web Services can easily use in caching feature of asp.net.
- With the help of Web Services,we can easily integrate asp.net web application with third party systems.
- Web Services is useful in security purpose as ssl and window authentication of asp.net application.
Examples of Web Services
There are some example of Web Services which are given below:-
1. )
Suppose we want to host a website(asp.net,php ,java etc) on the server
that calculate the simple interest.For this, we can use a web service to
calculate the simple interest.In this scenario,we do not need to write
codes in the website for calculating the simple interest. We do not
put calculating simple interest code inside the website,for this we can
create a Web Service which can calculate the simple interest.Here Our website performs two things,
- Take input from client side (end user) using Text Box.
- Display the output to the client end ( Calculating the simple interest by the Web Service).
2. ) Preparing the pay slip for employee by a company
3. ) Display the weather report on the website
4. ) Calculate the simple interest and income tax of the banks and income tax departments.
5. ) Display the New News (Notification) Headlines on the website.
Real Life Example of Web Services
I think almost every people know about TV and TV channels. There are many company which manufactures TV as
- Sony
- Samsung
- LG
- Vediocon
- Others
There are some service providers (TV Channels) which provide the services as
- Airtel Digital
- Dish
- Reliance Digital
- Tata sky
- Vediocon d2h
- Sun direct
- others
Similarly we can compare TV --to-> Website and TV Channels (services) --to->Web Services.
Here peoples
are using different TV and Channels to use the services.They are not
facing any type of problems by using this different TV and TV
Channels.Same concepts are used in website and web services also.
Similarly we can use different website (asp.net ,php, java, etc) and
different web services for performing any task. We can use any web
services in different platform.Web services are used XML language for communication to the website .You already know XML is platform independent .
There are some standard used by web services in ASP.NET which are given below:-
1. ) HTTP
:- It is known as Hyper Text Transfer Protocol .All Internet protocols
follow some rules.It is a connection less protocol.This protocol is
used to transmit the data between web services and it users
(website),Such as HTTP-GET and HTTP-POST.A web service can use any
remote procedure call (RPC) protocols,such as DCOM (Distributed
component object model ) or Common object Request Broker Architecture
(CORBA),to transmit data HTTP-GET and HTTP-POST protocols used by the
web services to transmit the data over the Internet.By default HTTP-GET
and HTTP-POST bindings are not enabled to Remote web service invocation.
2. ) XML :-
It is known as Extensible Markup Language.It is a standard used by all
web services to transfer the data.It is platform independent.So that e
can use web services on any website without facing platform
compatibility problem.
Note:-You can define an XML web service as a unit of code that can be invoked via HTTP Requests.
3. ) WSDL :- It
is Known as Web Service Description Language.It is a standard used by
the web service to describe what a web service can do.
WSDL is a
XML-based language that defines web services.Every web service holds
WSDL document that specifies the location of the web service and list of
all the services that the web service can perform. A WSDL document is a
simple XML document that containing different XML elements to define a
web service. I will show you all these standard when i will implement
web service in below section of this page.
There are some elements in WSDL Document which are given below:-
- Type :- It describe the all data types used in web service.
- Message :- It is describe the message which are used to communicate from one point to another when data is passed by the web service.
- Binding : - It describes the all protocols which are used by the web service.
- Port Type :- It describes the links of input and output message.
- Port :- It describe the address for binding the specific client port (end user port).
- Service :- It describes all services such as binding URL ,Port etc.
4. ) SOAP :-It
is known as Simple object access protocol.It is a standard used by the
web service to send the response (or request) message to the application
(website).It is completely XML based protocol.SOAP provides a complete
set of rules for messaging.One of the great advantage of using a SOAP
message is that ,it is not restricted to any one operating system.
5. ) DISCO.exe :-
It is known as the web service discovery tool,It is used for publishing
and discovering web services.This tool is helpful to discover URL of
all the web services located on a web server and creates a list of them
in a file,called DISCO file (with .disco extension).
Note:- This file mostly can be accessed by clients (users) to know about these kinds of services an organization provides.
6. ) UDDI :- It is known as Universal Description,Discovery and Integration .UDDI includes four types of services.
- Web service
- Business
- Binding
- Specifications
UDDI is a
central Directory where web services offered by different organization
are published.It is Built into the .net platform.It is platform
Independent.
Features of UDDI
- It stores the information of web services.
- It uses W3C & IETF standards (ex. XML,HTTP,DNS etc.).
- It uses SOAP for communication.
- It uses WSDL to describe interfaces to web services.
Advantages of Web Services
- It enhance the security feature of any website.
- It takes less processing time to calculate the logic code.
- It can easily handle multiple request at a time simultaneously.
- It is compatible to communicate with different platform.
- It follows XML ,HTTP Standards.
In this tutorial i am going to implement web service at different ways in .NET Application.Which are given below:-
How to call web services from the client end
There are
some steps to implement web service concepts in asp.net application.In
this application ,i have create a web service which can calculate
Addition,Subtraction, Multiplication, Division and modulus
operations.When user put two inputs on the website using Text Box then
this web service calculate the operations(Addition,Subtraction........)
and send output to the website(client end),after that website display
that output in script or Label.
Step -1 First open your visual studio --> File -->New -->Select ASP.NET Empty Website and select Visual C# from left window -->OK-->Now Open Solution Explorer-->Now Right click on website --> Add New Items --> Select web service & Visual C# --> Write your web service's name (calculationservices.asmx) --> click Add button as shown below:-
Step -2 Now Write the C# logic codes for calculation under [WebMethod] as given below:-
02 | using System.Collections.Generic; |
05 | using System.Web.Services; |
08 | /// Summary description for calculationservices |
11 | [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] |
14 | public class calculationservices : System.Web.Services.WebService { |
16 | public calculationservices () { |
22 | public string msdotnet() |
24 | return "welcome to www.msdotnet.co.in" ; |
27 | public int add( int i, int j) |
33 | public int substract( int i, int j) |
38 | public int multiply( int i, int j) |
44 | public int Division( int i, int j) |
50 | public int modulos( int i, int j) |
Step -3 Now Run this web services (calculationservices.asmx) -->Now copy the Browser's URL as shown below:-
Note
:- You can paste this URL on Notepad,MS Word etc. so that you can use
this URL ,when we will configure the web service on website.
Step -4 Now you can calculate your services(Addition,Subtraction,Multiplication,Division and modulus ) -->click Division link or others as show below:-
Step -5 Now click Invoke Button -->you will see ,output will show in XML Document format using SOAP Protocol.
Note :- You can calculate (test) all result using this method, your service is working or not.
Step -6 Now open your visual studio again--> File -->New -->Select ASP.NET Empty Website and select Visual C# from
left window -->OK-->Now Open Solution Explorer-->Now Right
click on website --> Add New Web Form (webservice.aspx) --> Drag
and drop Label ,Text Box and Button control on the Form as shown
below:-
Note :-
- web service extension --> .asmx
- Web Form Extension -->.aspx
- Disco File Extension -->.disco
Step -7 Now
open your solution Explorer -->Right Click on your application
(website) -->Add Web Reference -->Paste web service URL here
(Which i have already copied in step 3) -->Click Next Arrow as show
below:-
Note :- You can copy the URL by Run the web service again.
Step -8 Now Write the web service'Name (myservice) -->Click Add Reference Button.
as shown below :-
Step -9 You
will see ,there are some files are added in your application(when we
complete the web service configuration) as shown below:-
Note:- See above image carefully:-
- Include a Name space in webservice.aspx.cs file as Using myservice;
- Create object of calculationservices in webservice.aspx.cs file as calculationservices obj = new calculationservices();.
Step -10 Now write the c# codes on button click in webservice.aspx.cs file as given below:-
04 | using System.Web.UI.WebControls; |
06 | public partial class webservice : System.Web.UI.Page |
08 | protected void Page_Load( object sender, EventArgs e) |
12 | protected void Button1_Click( object sender, EventArgs e) |
14 | calculationservices obj = new calculationservices(); |
17 | int sum =obj.add(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text)); |
18 | Label1.Text = "Your addition Result =" + sum.ToString(); |
22 | protected void Button2_Click( object sender, EventArgs e) |
24 | calculationservices obj = new calculationservices(); |
25 | int sub = obj.substract(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text)); |
26 | Label1.Text = "Your Substraction Result =" +sub.ToString(); |
30 | protected void Button3_Click( object sender, EventArgs e) |
32 | calculationservices obj = new calculationservices(); |
33 | int mult = obj.multiply(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text)); |
35 | Label1.Text = "Your Multiplication Result =" +mult.ToString(); |
37 | protected void Button4_Click( object sender, EventArgs e) |
39 | calculationservices obj = new calculationservices(); |
40 | int div = obj.Division(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text)); |
41 | Label1.Text = "Your Divison Result =" + div.ToString(); |
45 | protected void Button5_Click( object sender, EventArgs e) |
47 | calculationservices obj = new calculationservices(); |
48 | int mod = obj.modulos(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text)); |
49 | Label1.Text = "Your Modulos Result =" + mod.ToString(); |
Step -11 Now Run the Application (webservice.aspx) (press F5) -->Enter the Text Box Fields -->press each button( Add, Subtract......... )as shown below:-
No comments:
Post a Comment