A
Arpan
I successfully created a DLL named "DBServices.dll" using the following
code in a class file:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Services
Namespace DBServices
Public Class DBServiceSettings : Inherits WebService
Private sqlConn As SqlConnection
<WebMethod()> Public Function QueryDB(ByVal Query As String) As
DataSet
Dim dSet As DataSet
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection("Data Source=......")
sqlDapter = New SqlDataAdapter(Query, sqlConn)
dSet = New DataSet
sqlDapter.Fill(dSet, "tblName")
Return dSet
End Function
End Class
End Namespace
This is 1-line code in the ASMX page that uses the above DLL to create
a web service:
<%@ WebService Language="VB" Class="DBServices.DBServiceSettings" %>
As such the above ASMX page gets executed perfectly. When the user
comes to the ASMX page, "QueryDB" is rendered as a link clicking which
the next page displays a TextBox to enter a SELECT SQL query. When the
user clicks the "Invoke" Button in the next page, a new browser window
opens up & displays all the records retrieved by the SQL query in XML
format.
Now I did like to cache the web service. Had the code in the class file
existed in the ASMX page, I could have used the CacheDuration property
of the WebMethod attribute but since the class file encapsulates the
logic, I can't use the CacheDuration property in the WebMethod
attribute.
So how do I cache the web service in this case?
Thanks,
Arpan
code in a class file:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Services
Namespace DBServices
Public Class DBServiceSettings : Inherits WebService
Private sqlConn As SqlConnection
<WebMethod()> Public Function QueryDB(ByVal Query As String) As
DataSet
Dim dSet As DataSet
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection("Data Source=......")
sqlDapter = New SqlDataAdapter(Query, sqlConn)
dSet = New DataSet
sqlDapter.Fill(dSet, "tblName")
Return dSet
End Function
End Class
End Namespace
This is 1-line code in the ASMX page that uses the above DLL to create
a web service:
<%@ WebService Language="VB" Class="DBServices.DBServiceSettings" %>
As such the above ASMX page gets executed perfectly. When the user
comes to the ASMX page, "QueryDB" is rendered as a link clicking which
the next page displays a TextBox to enter a SELECT SQL query. When the
user clicks the "Invoke" Button in the next page, a new browser window
opens up & displays all the records retrieved by the SQL query in XML
format.
Now I did like to cache the web service. Had the code in the class file
existed in the ASMX page, I could have used the CacheDuration property
of the WebMethod attribute but since the class file encapsulates the
logic, I can't use the CacheDuration property in the WebMethod
attribute.
So how do I cache the web service in this case?
Thanks,
Arpan