Visual Studio 2010 で vb.net を使用して作成した .asmx Web サービスがあります。最近、以下のクエリを修正し、「, geography::Point(@Latitude, @Longitude, 4326).STDistance(Location) * 0.00062137119」を追加しました。while reader.Read() ループに追加して、webservice の xml に 10 進数を文字列として出力する必要があることを追加したので、行 fuelStop.Distance = reader.GetString(5) は明らかに機能しません。距離をxmlに出力するには?
Web サービス コード:
<WebMethod()> _
Public Function GetFuelStops(ByVal Latitude As Double, ByVal Longitude As Double) As FuelStop()
Dim resultList = New List(Of FuelStop)()
Using sqlCon As New SqlConnection()
sqlCon.ConnectionString = "Data Source=(local);Initial Catalog=My_DB;User ID=*****;Password=*******"
Dim sql = <sql>
DECLARE @center GEOGRAPHY
SET @center = geography::Point(@Latitude, @Longitude, 4326)
SELECT TOP 10
[Physical_Address_Street]
, [Physical_Address_Local]
, [Physical_Address_State]
, [Physical_Address_Zip]
, [Phone_Number]
, geography::Point(@Latitude, @Longitude, 4326).STDistance(Location) * 0.00062137119
FROM Gas_Stations
WHERE Location_Type = 1
ORDER BY @center.STDistance(Location) ASC
</sql>
Dim command As New SqlCommand()
command.CommandText = CStr(sql)
command.Parameters.Add("@Latitude", SqlDbType.Decimal).Value = Latitude
command.Parameters.Add("@Longitude", SqlDbType.Decimal).Value = Longitude
command.Connection = sqlCon
sqlCon.Open()
Using reader = command.ExecuteReader()
While reader.Read()
Dim fuelStop = New FuelStop()
fuelStop.Physical_Address_Street = reader.GetString(0)
fuelStop.Physical_Address_Local = reader.GetString(1)
fuelStop.Physical_Address_State = reader.GetString(2)
fuelStop.Physical_Address_Zip = reader.GetString(3)
fuelStop.Phone_Number = reader.GetString(4)
fuelStop.Distance = reader.GetString(5)
resultList.Add(fuelStop)
End While
End Using
End Using
Return resultList.ToArray()
End Function
そして、ここに私の FuelStop.class があります
Public Class FuelStop
Property Physical_Address_Street As String
Property Physical_Address_Local As String
Property Physical_Address_State As String
Property Physical_Address_Zip As String
Property Phone_Number As String
Property Distance As String
End Class