I have the following code:
I want to convert it to a web service and im not sure how to do it.
Sub Search(ByVal intSearchType As Search.enmSearchType)
Try
Dim objSearch As New Search
Dim objSearchInst As New Search
Dim intResult As Integer
Dim objList As New ArrayList
panSearch.Visible = True
If Len(txtSearch.Text) < 3 Then
txtResults.Text = "Enter at least 3 characters to do a search"
Exit Sub
End If
intResult = objSearch.SearchByKeyword(txtSearch.Text, Session("Person"), Session("Office"), Session("Organisation"), _
Session("Role"), intSearchType, objList)
If intResult <> 0 Then
txtResults.Text = "Oops. There was a problem performing the search, please try again later"
Exit Sub
End If
txtResults.Text = ""
For Each objSearchInst In objList
txtResults.Text += "<a href='#' class=lnks önclick=""return OpenWindow('../contactmanagement/contact.aspx?PersonRef=" & objSearchInst.Return1 & "',750,600)"">#" & objSearchInst.Return1 & ": " & objSearchInst.Return2 & " " & objSearchInst.Return3 & "</a><br/>"
Next
If txtResults.Text = "" Then
txtResults.Text = "no matching records found"
End If
Catch ex As Exception
txtResults.Text = "Oops. There was a problem performing the search, please try again later"
End Try
End Sub
I have tried the following:
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
Public Function ContactGet(ByVal searchField As String) As String
Dim objSearch As New ArrayList
Dim objSearching As New Search
Dim intResult As Integer
Try
intResult = objSearching.SearchByKeyword(searchField, str_person_ref, str_office_ref, str_organization_ref, _
str_role_ref, compX.ETMyProperty.Search.enmSearchType.enmContact, objSearch)
Dim objContact As New Person
Dim dt As New DataTable("Contacts")
Dim col_Name As New DataColumn("Name", GetType(String))
dt.Columns.Add(col_Name)
Dim col_Mobile As New DataColumn("Mobile", GetType(String))
dt.Columns.Add(col_Mobile)
Dim col_Office As New DataColumn("ContactNum", GetType(String))
dt.Columns.Add(col_Office)
Dim col_Category As New DataColumn("Category", GetType(String))
dt.Columns.Add(col_Category)
Dim dr As DataRow
For i = 0 To objSearch.Count - 1
dr = dt.NewRow()
dr("Name") = DirectCast(objSearch(i), compX.ETMyProperty.Search).SearchByKeyword(searchField, Session("Person"), Session("Office"), Session("Organisation"), _
Session("Role"), compX.ETMyProperty.Search.enmSearchType.enmContact, objSearch)
dr("Mobile") = DirectCast(objSearch(i), compX.ETMyProperty.Search).SearchByKeyword(searchField, Session("Person"), Session("Office"), Session("Organisation"), _
Session("Role"), compX.ETMyProperty.Search.enmSearchType.enmContact, objSearch)
dr("ContactNum") = DirectCast(objSearch(i), compX.ETMyProperty.Search).SearchByKeyword(searchField, Session("Person"), Session("Office"), Session("Organisation"), _
Session("Role"), compX.ETMyProperty.Search.enmSearchType.enmContact, objSearch)
dr("Category") = DirectCast(objSearch(i), compX.ETMyProperty.Search).SearchByKeyword(searchField, Session("Person"), Session("Office"), Session("Organisation"), _
Session("Role"), compX.ETMyProperty.Search.enmSearchType.enmContact, objSearch)
dt.Rows.Add(dr)
Next
Dim serializer As New JavaScriptSerializer()
Dim rows As New List(Of Dictionary(Of String, Object))()
Dim row As Dictionary(Of String, Object) = Nothing
For Each drow As DataRow In dt.Rows
row = New Dictionary(Of String, Object)()
For Each col As DataColumn In dt.Columns
row.Add(col.ColumnName, dr(col))
Next
rows.Add(row)
Next
Dim str_json = JsonConvert.SerializeObject(dt, Formatting.Indented)
Return str_json
Catch ex As Exception
Return Nothing
End Try
End Function
When I run the webservice and I invoke it i get:
<string xmlns="http://compX.net/">[]</string>
and I am not sure what that means.
So basically I want to know is my conversion correct and what does my result mean? Any suggestions?
c# help also welcome