How to create basic webservices including webmethod which returns string data as well as webmethod which returns XML record set from SQL Server database.
At database part no special table need to be created it uses default database and tables in SQL Server 7 intallation.
This example will let you know and make you familiar with basic webservices concepts although i have commented the codes but if you still have any problem in understanding the code please let me know.
--------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'
' This code was generated by a tool.
' Runtime Version: 1.1.4322.510
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
'
'------------------------------------------------------------------------------
Option Strict Off
Option Explicit On
Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
'
'This source code was auto-generated by Microsoft.VSDesigner, Version 1.1.4322.510.
'
Namespace localhost
'
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Web.Services.WebServiceBindingAttribute(Name:="DataService1Soap", [Namespace]:="http://tempuri.org/DataService1/Service1")> _
Public Class DataService1
Inherits System.Web.Services.Protocols.SoapHttpClientProtocol
'
Public Sub New()
MyBase.New
Me.Url = "http://localhost/DataService1/Service1.asmx"
End Sub
'
_
Public Function Add(ByVal a As Integer, ByVal b As Integer) As Integer
Dim results() As Object = Me.Invoke("Add", New Object() {a, b})
Return CType(results(0),Integer)
End Function
'
Public Function BeginAdd(ByVal a As Integer, ByVal b As Integer, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("Add", New Object() {a, b}, callback, asyncState)
End Function
'
Public Function EndAdd(ByVal asyncResult As System.IAsyncResult) As Integer
Dim results() As Object = Me.EndInvoke(asyncResult)
Return CType(results(0),Integer)
End Function
'
_
Public Function Multiply(ByVal a As Integer, ByVal b As Integer) As Double
Dim results() As Object = Me.Invoke("Multiply", New Object() {a, b})
Return CType(results(0),Double)
End Function
'
Public Function BeginMultiply(ByVal a As Integer, ByVal b As Integer, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("Multiply", New Object() {a, b}, callback, asyncState)
End Function
'
Public Function EndMultiply(ByVal asyncResult As System.IAsyncResult) As Double
Dim results() As Object = Me.EndInvoke(asyncResult)
Return CType(results(0),Double)
End Function
'
_
Public Function RetrieveData(ByVal sql As String) As System.Data.DataSet
Dim results() As Object = Me.Invoke("RetrieveData", New Object() {sql})
Return CType(results(0),System.Data.DataSet)
End Function
'
Public Function BeginRetrieveData(ByVal sql As String, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("RetrieveData", New Object() {sql}, callback, asyncState)
End Function
'
Public Function EndRetrieveData(ByVal asyncResult As System.IAsyncResult) As System.Data.DataSet
Dim results() As Object = Me.EndInvoke(asyncResult)
Return CType(results(0),System.Data.DataSet)
End Function
End Class
End Namespace