Writing the cleint side to a web service

hewstone999

New member
Joined
Feb 24, 2009
Messages
2
Programming Experience
Beginner
I have created a website service (see code below) that gets information from the database. However i am now stuck on creating the Client side. I have included code after the web service of what ive done so far for the client side.

Webservice code......
VB.NET:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Friend Class connectionFactory
Private msConnectionString As String

Public Sub New(ByVal ConnectionString As String)
msConnectionString = ConnectionString
End Sub

Public Sub New()
msConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=R: C:\events.mdb"
End Sub

Friend Function getConnection() As Data.OleDb.OleDbConnection
Dim oConnection As New Data.OleDb.OleDbConnection(msConnectionString)
oConnection.Open()
Return oConnection
End Function
End Class

Friend Class eventCommands
Public Function getEventsForDateHTML(ByVal eventDate As Date, ByVal OleConn As Data.OleDb.OleDbConnection) As Data.DataTable
Dim oDataSet As Data.DataSet
Dim oDTable As System.Data.DataTable
Dim oDRow As System.Data.DataRow
oDataSet = getEventsbyDate(eventDate, OleConn)
Return oDataSet.Tables(0)
End Function


Private Function getEventsbyDate(ByVal eventDate As Date, ByVal OleConn As Data.OleDb.OleDbConnection) As Data.DataSet
Dim oDataSet As New Data.DataSet("Events")
Dim oAdapt As New Data.OleDb.OleDbDataAdapter()
Dim sQuery As String
sQuery = "Select * from tblEvents where EventDate = #" & eventDate.ToString & "#"
oAdapt.SelectCommand = New Data.OleDb.OleDbCommand(sQuery, OleConn)
oAdapt.Fill(oDataSet)
Return oDataSet
End Function

Public Function getCategories(ByVal OleConn As Data.OleDb.OleDbConnection) As Data.DataTable
Dim oDataSet As New Data.DataSet("Categories")
Dim oDSTable As Data.DataTable, oDRow As System.Data.DataRow
Dim oAdapt As New Data.OleDb.OleDbDataAdapter()
Dim sQuery As String, sOut As String
oAdapt.SelectCommand = New Data.OleDb.OleDbCommand("Select iCategoryID, Category from tblCategories order by Category", OleConn)
oAdapt.Fill(oDataSet, "Categories")
Return oDataSet.Tables(0)
End Function

Public Function getEventsByDateAndCategoryID(ByVal eventDate As Date, ByVal catID As Integer, ByVal OleConn As Data.OleDb.OleDbConnection) As Data.DataTable
Dim oDataSet As New Data.DataSet("Events")
Dim oAdapt As New Data.OleDb.OleDbDataAdapter()
Dim sQuery As String
sQuery = "Select * from tblEvents where EventDate = #" & eventDate & "# and CategoryID =" & catID
oAdapt.SelectCommand = New Data.OleDb.OleDbCommand(sQuery, OleConn)
oAdapt.Fill(oDataSet)
Return oDataSet.Tables(0)
End Function
End Class

Public Class Events
'The Event Class gets the user or app what they need
Private oconnFactory As New connectionFactory("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\events.mdb")

Public Function getEventsHTML(ByVal dt As Date) As String
Dim oconn As Data.OleDb.OleDbConnection = oconnFactory.getConnection()
Dim oEventCommands As New eventCommands()
Dim oDTable As Data.DataTable = oEventCommands.getEventsForDateHTML(dt, oconn)
Return createHTMLEventTable(oDTable)
End Function

Public Function getEventsByCategoryHTML(ByVal dtEvent As Date, ByVal iCat As Integer) As String
Dim oconn As Data.OleDb.OleDbConnection = oconnFactory.getConnection()
Dim oEventCommands As New eventCommands()
Dim oDTable As Data.DataTable = oEventCommands.getEventsByDateAndCategoryID(dtEvent, iCat, oconn)
Return createHTMLEventTable(oDTable)
End Function

Public Function getCategoryOptionList() As String
Dim oconn As Data.OleDb.OleDbConnection = oconnFactory.getConnection()
Dim oEventCommands As New eventCommands()
Dim oDSTable As Data.DataTable = oEventCommands.getCategories(oconn)
Dim oDRow As Data.DataRow
Dim sOut As String
sOut = vbNullString
For Each oDRow In oDSTable.Rows
sOut &= "<option value=" & oDRow.Item("iCategoryID") & ">" & oDRow.Item("Category") & "</option>"
Next
oconn.Close()
Return sOut
End Function

Private Function createHTMLEventTable(ByVal EventDataTable As Data.DataTable) As String
Dim strOut As String
Dim oDRow As Data.DataRow
For Each oDRow In EventDataTable.Rows
strOut &= oDRow.Item("EventDate")
strOut &= oDRow.Item("EventName")
strOut &= oDRow.Item("EventSponsor")

Next

oDRow = Nothing
EventDataTable = Nothing
Return strOut
End Function
End Class


Public Class Service
Inherits System.Web.Services.WebService

<WebMethod()> Public Function EventCategoryOptions() As String
Dim oEvents As New Global.Events()
EventCategoryOptions = oEvents.getCategoryOptionList()
End Function
<WebMethod()> Public Function getEventsByDate(ByVal EventDate As Date) As String
Dim oEvents As New Global.Events()
getEventsByDate = oEvents.getEventsHTML(EventDate)
End Function
<WebMethod()> Public Function getEvntsByDateAndCat(ByVal EventDate As Date, ByVal Category As Integer) As String
Dim oEvents As New Global.Events()
getEvntsByDateAndCat = oEvents.getEventsByCategoryHTML(EventDate, Category)
End Function

End Class

Client code:
Partial Class _book
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fr As AccessDatabaseConnection.Service
fr = New AccessDatabaseConnection.Service
fr.getEventsByDate(txtFlightNum.Text)

BulletedList1.DataSource = fr.getEventsByDate(txtFlightNum.Text)
BulletedList1.DataBind()

End Sub
End Class

Note: i want to output the results to a bullet point list however the results come up like this
-1
-0
-/
-0
-9
-/
-2
-0
-0
-9

and i want it to output like this:
-10/09/2009
 
Back
Top