This article and the accompanying source code show you the. NET development environment, how to create a Web service is simple and demonstrates how clients use this Web service. The routine creates a simple Web service for a calculator that has three methods: Add, subtract, and divide.
Download Package Webservice_mehta.zip contains all the demo files: calculator.asmx
Htmlclient.html
Inetclient (VB6 Project)
Calculator.asmx Code
<%@ WebService Language = "Vb" class= "Calculator"%>
' This example demonstrates a simple Web service
' Calculator has three Web methods for basic computing
' Tag <webmethord () > Export method
Option Strict Off
Imports System.Web.Services
Public Class calculator:inherits WebService
Public Function <webmethod () > Add (Num1 as integer,num2 as Integer)
As Integer
return NUM1 + Num2
End Function
Public Function <webmethod () > Substract (Num1 as integer,num2 as
Integer) as Integer
Return num1-num2
End Function
Public Function <webmethod () > Divide (Num1 as integer,num2 as
Integer) as Integer
Return num1/num2
End Function
End Class
Calculator.asmx has three methods, both accepting parameters Num1 and Num2, and then performing the arithmetic calculation to return an integer value.
Under IIS, publish Calculator.asmx to any one of the virtual directories, accessed from the browser, as follows:
You'll see a "Calculator Web Service" Description page that shows three methods that are exported and can be invoked on the same page.
Creating an HTML Client
<body bgcolor = pink>
<form id = frm method=post >
URL of the Web service, for example: Http://server/service1.asmx <br>
<input type = text id = servicelocation style= "WIDTH:
322px; " ><br><br>
NUM1: <input type= "Text" size= "5" name= ' Num1 ' "><br>
NUM2: <input type= "Text" size= "5" name= ' Num2 ' \ "><br><br> <input type = Button Value = Add onclick =" ADD () ">
<input type = Button Value = minus onclick = "substract ()" >
<input type = button Value = except onclick = "Divide ()" >
</form>
<script Language = "VbScript" >
Sub ADD
MsgBox frm. Servicelocation.value
Frm.action = frm. Servicelocation.value & "/add"
Frm.submit
End Sub
Sub Substract
Frm.action = frm. Servicelocation.value & "/substract"
Frm.submit
End Sub
Sub Divide
Frm.action = frm. Servicelocation.value & "/divide"
Frm.submit
End Sub
</script>
</body>
The client page submits data to the Calculator.asmx Web Service page, and the result returned is in XML form.
WinInet Client
The WinInet client uses the Win32 user interface to accept data and then submits it to the CALCULATOR.ASXM Web service, and the returned XML results are displayed as text by the client-side analysis extraction.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.