Here it is ... my vbform :
form fields : streettxt , citytxt, statetxt , datagridview Resultsdgv
form button : CallWebServicebtn
here's the code :
Imports
System
Imports
System.Data
'Imports System.Data.SqlClient
'Imports System.Data.SqlTypes
'Imports Microsoft.SqlServer.Server
Imports
System.Net
Imports
System.Xml
Imports
System.Xml.XPath
Imports
System.Text
Public
Class FormStartup
Private Sub CallWebServicebtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CallWebServicebtn.Click
Dim ds As New DataSet
Try
ds = SPCLR_Geocode(Streettxt.Text.ToString, Citytxt.Text.ToString, Statetxt.Text.ToString,
"myyahootestappid")
If ds.Tables.Count > 0 Then
Resultdgv.DataSource = ds.Tables(0)
Else
Resultdgv.DataSource =
Nothing
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Public Function SPCLR_Geocode(ByVal Address As String, ByVal City As String, ByVal State As String, ByVal appid As String) As DataSet
'Declare string for URL
Dim URL As String = "_empty_"
'Yahoo test appid "myyahootestappid"
Try
'Replace the spaces in your Address with the plus sign to build the URL needed for Yahoo
Address = Address.Replace(
" ", "+")
'Build the URL
URL =
"http://api.local.yahoo.com/MapsService/V1/geocode?appid=" + appid + "&street=" + Address + "&city=" + City + "&state=" + State
'
'Get the XML response
Dim xmlread As New XmlTextReader(URL)
' Create the record and specify the metadata for the columns.
'Dim record As New SqlDataRecord(New SqlMetaData("Latitude", System.Data.SqlDbType.VarChar, 100), New SqlMetaData("Longitude", System.Data.SqlDbType.VarChar, 100), New SqlMetaData("GeoCodedAddress", System.Data.SqlDbType.VarChar, 100), New SqlMetaData("GeoCodedCity", System.Data.SqlDbType.VarChar, 100), New SqlMetaData("GeoCodedState", System.Data.SqlDbType.VarChar, 2), New SqlMetaData("GeoCodedZip", System.Data.SqlDbType.VarChar, 10), New SqlMetaData("GeoCodedCountry", System.Data.SqlDbType.VarChar, 10), New SqlMetaData("Precision", System.Data.SqlDbType.VarChar, 100), New SqlMetaData("Warning", System.Data.SqlDbType.VarChar, 100))
'Create a Dataset to hold the results
Dim ds As New DataSet()
'Fill the DS
ds.ReadXml(xmlread)
' Mark the begining of the result-set.
' SqlContext.Pipe.SendResultsStart(record)
'If the response included an error, then the array length is different, 0-7
'If ds.Tables(0).Rows(0).ItemArray.Length.Equals(9) Then
' record.SetString(0, ds.Tables(0).Rows(0).ItemArray(0).ToString())
' record.SetString(1, ds.Tables(0).Rows(0).ItemArray(1).ToString())
' record.SetString(2, ds.Tables(0).Rows(0).ItemArray(2).ToString())
' record.SetString(3, ds.Tables(0).Rows(0).ItemArray(3).ToString())
' record.SetString(4, ds.Tables(0).Rows(0).ItemArray(4).ToString())
' record.SetString(5, ds.Tables(0).Rows(0).ItemArray(5).ToString())
' record.SetString(6, ds.Tables(0).Rows(0).ItemArray(6).ToString())
' record.SetString(7, ds.Tables(0).Rows(0).ItemArray(7).ToString())
' record.SetString(8, ds.Tables(0).Rows(0).ItemArray(8).ToString())
' 'If the response did not include an error, then the array length is 0-6
'Else
' record.SetString(0, ds.Tables(0).Rows(0).ItemArray(0).ToString())
' record.SetString(1, ds.Tables(0).Rows(0).ItemArray(1).ToString())
' record.SetString(2, ds.Tables(0).Rows(0).ItemArray(2).ToString())
' record.SetString(3, ds.Tables(0).Rows(0).ItemArray(3).ToString())
' record.SetString(4, ds.Tables(0).Rows(0).ItemArray(4).ToString())
' record.SetString(5, ds.Tables(0).Rows(0).ItemArray(5).ToString())
' record.SetString(6, ds.Tables(0).Rows(0).ItemArray(6).ToString())
' record.SetString(7, "Precision Good")
' record.SetString(8, "No Error")
'End If
'SqlContext.Pipe.SendResultsRow(record)
' Mark the end of the result-set.
'SqlContext.Pipe.SendResultsEnd()
Return ds
Catch ex As Exception
Throw New Exception(String.Format("AT_Error with url [{0}]", URL.ToString), ex)
End Try
End Function
End
Class
it also gives an error, but for some proxi thing ???
System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required.
at System.Net.HttpWebRequest.GetResponse()
at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlReader.MoveToContent()
at System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving)
at System.Data.DataSet.ReadXml(XmlReader reader)
at GeocodingWIN.FormStartup.SPCLR_Geocode(String Address, String City, String State, String appid) in P:\Documents\Visual Studio 2005\Projects\Geocoding\GeocodingWIN\FormStartup.vb:line 56"
Being a dba that's trying to code a bit ... HEEELLLLPP
http://api.local.yahoo.com/MapsService/V1/geocode?appid=mytestcode&street=8&city=Seattle&state=WA
once again, internet exporer with the same url works fine
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me