The ImageInfoService class defines the ImageInfoProvider Web service.
Listing 6-6 shows the code for the ImageInfoService.asmx.vb class:
Imports System.Web.Services Imports System.Data.SqlClient Imports System.IO <System.Web.Services.WebService(Namespace:="http://tempuri.org/ImageInfoProvider/ImageInfoService")> _ Public Class ImageInfoService Inherits System.Web.Services.WebService Dim sqlConn As New SqlConnection <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() components = New System.ComponentModel.Container 'Retrieving the connection string from a text file, Settings.txt. Dim sqlConnectionString As String Try Dim sr As New StreamReader(Server.MapPath(".") & "\Settings.txt") sqlConnectionString = sr.ReadLine sr.Close() Catch ex As Exception 'If there is error accessing the Settings.txt file sqlConnectionString = "SERVER=localhost;UID=sa;PWD=sa;Initial Catalog=CoverDesigner" End Try 'Try establishing connection to CoverDesigner database Try 'Specifying the connection string for opening the connection sqlConn.ConnectionString = sqlConnectionString sqlConn.Open() Catch ex As Exception 'Error establishing connection End Try End Sub 'This method returns information regarding the image whose information is 'requested by the Visio drawing in the cover designer application. <WebMethod()> _ Public Function getImageInfo(ByVal imageCategoryId As Integer, ByVal imageFileName As String) As DataSet Dim ds As New DataSet Try Dim sqlcmd As New SqlCommand("select * from images where imagecategoryId=" & _ imageCategoryId & " and imageFilename='" & imageFileName & "'", sqlConn) Dim sqlda As New SqlDataAdapter(sqlcmd) sqlda.Fill(ds) Return ds Catch ex As Exception 'Error in retrieving images information from database 'Return empty dataset Return ds End Try End Function End Class
Download this Listing .
The above listing implements the getImageInfo method, which returns a dataset containing the information for the image selected by the end user .