- The web services is an entity that you can develop to provide particular functionality over the internet.
- For example weather information, live score of cricket, simple and compound interest formula.
- For such purposes, you make a web service for each. It will use not only for one website but also for many other websites those are providing same facilities.
- The developer just needs to consume the web services and then its required function is working.
- So, it is better to develop a web service common to all instead of writing the same business logic for all websites.
- Web service provides common functionalities and results for all websites.
- Irrespective of any programming language as web service is based on XML so can be useful to all language based applications.
- Web Service messages are formatted as XML, a standard way for communication between two incompatible system, and this message is sent via HTTP so that they can reach to any machine on the internet without being blocked by the firewall.
A web services Like
- Language Independent.
- Protocol Independent.
- Platform Independent.
- It assumes stateless service architecture.
- Scalable (e.g. multiplying two numbers together to an entire customer-relationship management system).
- Programmable (encapsulates a task).
- Based on XML (open, text-based standard).
- Self-describing (metadata for access and use).
- Discoverable (search and locate in registries)- the ability of applications and developers to search for and locate desired Web services through registries. This is based on UDDI.
Creating a Web Services
Let us write a simple module that will provide basic arithmetic operations to other applications. The user of this application will have to provide us 2 numbers and it will perform the requested operation like Addition, Subtraction, and Multiplication.
So, the first thing to do is to create our web service. This can be done by creating a website of type ASP.NET Web service. This will give a skeleton to write web service code.
Consuming a web services
There are three ways we can consume web services:
- Using HTTP-POST method.
- Moreover, Using XMLHttp that will use SOAP to call our the service
- Using WSDL generated proxy class
1) The HTTP-Post method can use by calling .asmx file directly from the client. We can directly use the method name and the parameter names will take from our input fields on the form.
2) The second method where we can use the XMLHttp over SOAP to access the web service is used when we want to use the web service using the full capability of SOAP.
3) The third way of using the web service by generating a Proxy class for the web service and then using that proxy class. This method more type safe and less error prone as once we have the proxy class generated, it can take care of SOAP messages, serialization and ensure that all the problems can be handled at compile time instead of runtime. To use this service, we need to do “Add Web reference” and add the web service reference. Alternatively, we can also use WSDL.exe, a command line tool, to generate the proxy classes and use them. “Add Web Reference” also using the same WSDL.exe to generate the proxy classes