To create your first web service project, just follow these steps:
1. Open your Visual Studio .NET and click File > New Website. This will display the project templates. Choose ASP.NET Web Service from the installed templates as shown below.

2. Visual Studio .NET should generate your first Hello web service method. Lets tweak the code and add another web service method.
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
Inherits System.Web.Services.WebService
'<WebMethod()> indicates that this is a web service method
<WebMethod()> _
Public Function HelloFryan() As String
Return "Hello Fryan!"
End Function
<WebMethod()> _
Public Function AddThis(ByVal Num1 As Integer, ByVal Num2 As Integer) As Integer
Return Num1 + Num2
End Function
End Class
if you can notice the obvious difference of our web service method with an ordinary VB method is this additional attribute before the function name:
<WebMethod()> _
It tells the framework that the following method is a web service.
3. To test the web service project, Click the Start Debugging icon (play icon). Visual Studio will automatically open your default web browser and display all available web service method. (in this case we have two web methods)

4. Now lets test one of the web service method. Click the Addthis method. You should be forwarded to the following page:

AddThis requires two parameters. Try to put numbers on each textbox then click Invoke. The web service method will return an XML result like the one below:

There you have it, your first web service project. You can download the full sourcecode used on this project at Mediafire
For more ASP.NET tutorials, subscribe now
1 comments:
Great Tutorials.
Thanks so so much, every thing flows so well.
BTW, do you have some more material on ASP.NET, VB.NET web Services. Some kind of download-able e-book one can Buy. I really love the web service concept, but don't have sufficient tutorials.
my email is mwycliffe at gmail.com
Post a Comment