German Wear Discount Shop - Click Here Write for Dotnet-friends and earn for your each submission [Dot]Net-Friends
Skip Navigation Links
Home
Latest
Fast Code
Articles
Tutorials
Online Resources
Forums
Login   | Hi, Guest


Create a simple Web Service with Visual Studio 2005

Written by omerkamal on Jul 20, 2007
A simple web service in 8 steps

Explanation:


1. Start Visual Studio .NET or Visual Studio 2005.
2. Create a new Active Server Pages (ASP) .NET Web service project. Name the Web service MathService and point the location to an appropriate Web server that is running ASP.NET if necessary.
3. Change the name of the Solution file to MathService for consistency.
4. Change the name of the default Web service that is created from Service1.asmx to MathService.asmx.
5. Click Click here to switch to code view in the designer environment to switch to code view.

Change the name of the class from Public Class Service1 to Public Class MathService.
6. Define methods that encapsulate the functionality of your service. Each method that will be exposed from the service must be flagged with a WebMethod attribute in front of it. Without this attribute, the method will not be exposed from the service.

NOTE: Not every method needs to have the WebMethod attribute. It is useful to hide some implementation details called by public Web service methods or for the case in which the WebService class is also used in local applications. A local application can use any public class, but only WebMethod methods will be remotely accessible as Web services.


Add the following method to the MathServices class that you just created:

Public Function Add(a As Integer, b As Integer) As Integer
Return(a + b)
End Function

Public Function Subtract(A As System.Single, B As System.Single) As System.Single
Return A - B
End Function

Public Function Multiply(A As System.Single, B As System.Single) As System.Single
Return A * B
End Function

Public Function Divide(A As System.Single, B As System.Single) As System.Single
If B = 0
Return -1
End If
Return Convert.ToSingle(A / B)
End Function


7. Click Build on the Build menu to build the Web service.
8. Browse to the MathService.asmx Web service page to test the Web service. If you set the local computer to host the page, the URL is http://localhost/MathService/MathService.asmx.

The ASP.NET runtime returns a Web Service Help Page that describes the Web service. This page also enables you to test different Web service methods.
Visitors/Readers Comments
(for questions please use The Forum)



Sampson Orson Jackson
It was an excellent tutorial, I guess you should make one for consuming it...

13/12/2007 07:21:42 UTC

irshad

Good tips for biginners

15/05/2008 05:37:12 UTC




Add your Comments

Name:  
Message:
Note: For faster response please use Forums >> for your questions instead of the comments area! (Admin)