ASP.NET Training

ASP.NET Training – .asmx Webservice

Website structures are beginning to become more and more complex and we need help to further understand them. That is what this ASP.NET training is for and this will give you an intro into how this works. We use web services in order to improve website performance and save server-side processing used along with a number of other technologies like AJAX, XML, JSON for purpose of sending, receiving, encoding and decoding data. Web services are also a server-side response to client-side applications.

A web service is basically a class consist of methods that could be used by other applications. It used to follow a code-behind architecture like ASP.NET web pages, although it does not have a user interface. Webservices are used to enable to different applications on same or different systems to communicate with each other. Even through web services, a JAVA application can communicate C# application

In this tutorial, our focus will be

  • Creating a .asmx NET web service
  • Testing the created web service

Creating an ASP.NET .asmx Webservice

Before jumping into implementation, you need to know a few conventions.

Hypertext transfer protocol(HTTP) is used by web services for communication. Messaging protocol is SOAP, SOAP stands for Simple object access protocol, SOAP mes sages are in XML format.

For ASP.NET web service you have to install any version of Visual Studio, Visual Studio offers a lot of facilities and libraries for .NET development under a single app.

First open your Visual Studio IDE click on a new project, select Visual C# and create a new ASP.NET application project, name it as required and click ok.

 

After a little processing, you will reach on screen like this

Right click on project name go to add and click on add a new item

 

A pop-up window will show up, just scroll down to find a web service or search for web service via the search bar. Name the web service as required and click add.

.

 

Coding time!

Soon you will be redirected to a page like this where you already have some code and throughout the ASP.NET training, this will be your best friend.

 

“[WebService(Namespace = “http://tempuri.org/”)]” is used to identify your web service uniquely among millions of other web services, you can rename your service by adding text into the quotation marks after Namespace.

These are the system assemblies or classes you are accessing for the implementation of web services.

Here you have a sample web service which upon calling simply returns a Hello world in the form of a string. [Webmethod] is used to define a function is accessible from outside, if it’s not written before a function then that function or method will not be accessible from outside of that specific class.

Let’s add a simple web service which takes two integer parameters and return their sum.

 

 

 

 

 

After adding web service right click on project solution and rebuild the whole solution

 

After rebuilding solution right click on created web service and click on view in browser

You did it!

Click on view in browser web service and it will be displayed in browser such as this

asp.net training

 

HelloWorld and adder are the web services that you have created for your use you can click on any of them to see a response. Let’s click on the adder. Now that you have clicked on the adder, you will be redirected to a page where you can provide required parameters. 

Provide the parameter and then click on the Invoke button. The request will be passed to a web server and the response will be directly displayed as simple XML responses.

In order to understand response completely you must have to learn basics of XML first, but from the response, it is observable that response datatype was int and our result was 145.

Conclusion

In next tutorial we will move to advancements and will create a simple ASP.NET webpage and will consume web service through that, also we will explore basics of XML and SOAP. I hope you enjoyed this ASP.NET training as this is just the first installment. We will have another session coming soon! Please let us know what you think below and in the meantime, head over and check out a slick keyboard to help you with programming!

 

 

Newsletter


About Pat 26 Articles
I love to play the drums, build websites, learn tech, and explore! My passion is music and technology. I want to be in the fast lane of life, not the slow lane or the sidewalk.

Be the first to comment

Leave a Reply

Your email address will not be published.


*