What is a Web Service?
Imagine you own a business of gold jewelry. You build a website where users can browse your products, view their price and book them. Now, the price of gold fluctuates on an hourly basis and so does your jewelry. So how would you show the correct price of your products on a real-time basis? The solution to this lies in web services. Your software would demand the price of gold from other software every hour, let’s say a market index which updates gold prices instantly. Your software would then calculate the price of products based on the updated price. Then the consumers can book the products at the current price only to be picked up later from your store. Thus, a web service is simply a means of communication amongst software spread across the internet. There are obvious other jargons involved, such as XML, internet protocols, WSDL, SOAP, etc., but don’t worry. We will cover them all briefly throughout this asp.net web services article.
Definition of Web Services
A web service is a software program that uses XML to exchange information with other software over the internet via common internet protocols.
Definition of ASP.Net Web Services
ASP.Net Web service is simply a web service written in ASP.Net. Yes, believe it or not, this is as simple as that.
- XML – Extensible Markup Language. Tags that contain only data. Any application can format an XML into any desired format. XML is simply data inside tags.
- SOAP – Simple Object Access Protocol. A protocol that defines how XML based messages will be sent and received across applications.
- WSDL – Web Services Description Language. It describes the web services, their input expectations, their output descriptions and a summary of what a service can be used for. For e.g., there may be multiple services that provide the current rate of gold in multiple currencies and regions. So, a WSDL document summarises all those services. Interestingly, WSDL documents are also written in XML.
- UDDI – Universal Description, Discovery, and Integration. An XML-based standard that governs the creation and distribution of web services.
Why Web Services?
As always, before diving deeper into any topic, let us ask ourselves – why web services? What do they offer me? Why should I use web services? Let’s see.
Web services can be exchanged over the internet via various protocols. HTTP and UDP are two widely used ones.
Needless to describe, web services can be consumed in any platform or operating system.
Web services are stateless. This simply means that they provide information based only on the input parameters supplied to them. There is no other factor that alters the output for a set of inputs. I repeat, no other factor.
Due to the simple concept of providing information based on requests, web services are highly scalable. All consumer application must do is give inputs, and the web service would generate output for it. There are no fancy interfaces or stylish layouts. Just plain simple data in extremely light-weight XML format.
Imagine a bank which must decide whether to disburse loan to a client based on the client’s credit score. Now, instead of applying all the algorithms to calculate credit score in its own software, it can simply ask a credit agency to give the credit score of the client. Now imagine hundreds of banks leveraging the credit agency’s web service.
Thus, a complete task involving a humungous algorithm is encapsulated within a single program which is then exposed as a service and consumed by applications all over. Saves tonnes of effort, doesn’t it?
Through WSDLs, each web service can explain itself clearly.
Registrations through UDDI and unique URLs ensure that each web service across the globe is easily discoverable.
Creating an ASP.Net Web Service
Let’s hit the ground and create a simple ASP.Net Web Service which returns sample gold rate in different currencies.
Note: You would need Visual Studio installed in your machine for this activity.
- Open Visual Studio
- Go to File -> New -> Project
- Search for ‘web service’ in.Net Framework 3.5
- Select ‘ASP.Net Web Service Application Visual C#’.
- Name the project. I named it ‘sampleWebService’.
- Click Ok
- Visual Studio would create a basic web service application with the following code. This is ready to run the application and would simply display ‘Hello World’ when run.
- Change the code as below.
- Run the service. It will open the browser with the following link. Notice our method ‘SampleGoldRate’. Click on it.
- This opens the page where input parameters are expected. Enter the input parameter and click Invoke. This action would run the code and return the output in XML format.
- Notice the output below in XML format. This can easily be consumed by any other application.
- The description of the service can be simply accessed by appending ‘?wsdl’ at the end of the URL as below.
Congratulations on building your first ASP .NET Web Service.
Required ASP.Net Web Services Skills
Excited to build ASP.Net Web Services? Before you get hands-dirty, here is a little pre-requisite for learning ASP.Net Web Services. You must know the basics of programming and should have hands-on with the programming language C#. It is primarily recommended as it is the main ingredient of ASP.Net.
Also, it is recommended that before jumping on to ASP.Net Web Services you know about ASP.Net as well. If you do not know ASP.Net, don’t worry. Your learning curve will be slightly higher in such a case. If you already know ASP.Net, you are all set to explore more.
The above example was just a simple service. Of course, real-world applications are more complex. I would recommend diving in deeper and exploring more on how ASP.Net Web Services work and what is the underlying framework and libraries supporting it.
The career in ASP.Net Web Services
Web Services has a promising career. This is not because I claim the technology to last forever. No, Web Services just like any other technology will soon be overtaken by a better and innovative one. It still offers a strong career because the approach to solving problems using Web Services is going to stay in the market. There will be newer technologies developed, but all would be based on the concept of standardized communication between applications via globally accepted protocols. Combined with the power of ASP.Net, the potential is huge.
Thus, ASP.Net Web Services help you expose and consume codes. Once you get the hang of it, you could easily create complex algorithms and expose them as web services for other applications and software to consume.
This has been a guide to What is ASP.Net Web Services. Here we discussed the Basic Concept, Required Skills and Career growth of ASP.Net Web Services. You can also go through our other suggested articles to learn more –