punjabtechnicaluniversity.blogspot.in
.
This webservice will add two numbers and give to the calling client.All the below steps
are according to VS2005 beta editor :-
1.First create a website by clicking on File -- New WebSite.
2.From “Visual Studio Installed Templates” click on “Asp.NET Web Service”.See figure below.Name the figure as “Maths Web Service”.
After the webservice is done click on add Webreference.Normally for components we do a “Add Reference” and for Webservices we do “Add Web Reference”.
Your editor has located the “Maths” webservice.Select the webservice.
.
This webservice will add two numbers and give to the calling client.All the below steps
are according to VS2005 beta editor :-
1.First create a website by clicking on File -- New WebSite.
2.From “Visual Studio Installed Templates” click on “Asp.NET Web Service”.See figure below.Name the figure as “Maths Web Service”.
Create WebService Project
By default the .NET editor has made a default webservice method called as "HelloWord" which returns a string datatype.Let's rename "Service.vb" to "Maths.vb" and "Service.asmx" to "Maths.asmx".Let’s replace the “HelloWorld” with following code below :-
<WebMethod()> _
Public Function AddTwoNumbers(ByVal Number1 As Integer, ByVal
Number2 As Integer) As Integer
Return Number1 + Number2
End Function
Rename all your default “Service” to “Maths”
After the webservice is done click on add Webreference.Normally for components we do a “Add Reference” and for Webservices we do “Add Web Reference”.
Click on Add Web Reference
You will be shown with a list of webservices which are known to the solutions.As we are looking for our “Maths” webservice which exist in the samesolution , we click “Webservices in this solution”.
List of webservices for browsing
Your editor has located the “Maths” webservice.Select the webservice.
Solution showing the availability of Maths Webservice.
After you have clicked on “Maths” webservice you will see a search progress bar as shown in figure below.This process will start the webservice , reference it and create a proxy for the client , so that using it client can absorb the webservice.
Starting the webservice and creating the proxy for your solution.
Finally you are able to see your webservice which is ready for use.Click on Add Reference and you will see a “Localhost” reference in your .NET solution.
Starting the webservice and creating the proxy for your solution.
We need to make a client who will absorb this “Maths Webservice”.Add “WebserviceClient.aspx” and create a UI as shown below.In the button click put in the following code. ”LocalHost.ClsMaths” is the proxy object by which you can make calls to the webservice.
Sub cmdCalculate_Click(ByVal sender As Object, ByVal e AsSystem.EventArgs)
Dim pobjMaths As New localhost.ClsMaths
lblResultDisplay.Text =
Convert.ToString(pobjMaths.AddTwoNumbers(Convert.ToInt16(txtNumber1.Text),
Convert.ToInt16(txtNumber2.Text)))
End Sub
Complete Webservice in action.
Note :- The whole point of creating this “Maths Webservice” step by step was to have a understanding of practical angle of how webservices are created.It’s very very rare that you will be asked to explain every step of how to write a webservice.But in case your interviewer is too bend down to also know what are the actual steps in creating a Webservice.
0 comments:
Post a Comment
North India Campus