Dealing with .NET Enterprise Services: .NET Remoting, Web Services and Service Components - Working with Web Services
(Page 5 of 6 )
I want to demonstrate a very simple web service (like the first COM+ application) first. Let us consider the following code:
<WebMethod()> _
Public Function getSum(ByVal a As Integer, ByVal b As
Integer)
Return (a + b)
End Function
<WebMethod()> _
Public Function getProduct(ByVal a As Integer, ByVal b As
Integer)
Return (a * b)
End Function
Really, it is very exciting to work with Web Services within the Visual Studio environment. You cannot just leave it, once you get habituated. It is such a productive environment that you can develop a simple web service (like the one above) in a minute or less.
Coming to the above scenario, all the methods within a web service are to be preceded with an attribute “<WebMethod()>”. This lets IIS know that the method could be accessed by any other remote access client through http!
The client code to access the same is very simple. You can take a look at the following:
Private Sub btnSum_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSum.Click
Dim srv As New Calculate.CalcService
lblResult.Text = srv.getSum(CInt(Me.txtFirst.Text), CInt
(Me.txtSecond.Text))
End Sub
Private Sub btnProduct_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnProduct.Click
Dim srv As New Calculate.CalcService
lblResult.Text = srv.getProduct(CInt(Me.txtFirst.Text),
CInt(Me.txtSecond.Text))
End Sub
The web service is named “Calculate.CalcService”. Just create an object on that and access the members!
Next: Working with database based Web Services >>
More .NET Articles
More By Jagadish Chaterjee