我正在通过 asp.net 创建一个 Web 服务。我想将加油站的地址作为一个列表拉出来,如下所示不幸的是,我得到的是地址的字符串名称,如下所示来自 xml...
不幸的是,当我运行它时,我得到一个 xml 文件
-<FuelStop>
<Physical_Address_Street>Physical_Address_Street</Physical_Address_Street>
<Physical_Address_Local>Physical_Address_Local</Physical_Address_Local>
<Physical_Address_State>Physical_Address_State</Physical_Address_State>
<Physical_Address_Zip>Physical_Address_Zip</Physical_Address_Zip>
<Phone_Number>Phone_Number</Phone_Number>
</FuelStop>
与获取数据库中填充的地址信息相比。
下面是我的代码。
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
<System.Web.Services.WebService(Namespace:="http://watersports.com 8010/", Description:="Holds Fuel Stop and Shelter information", Name:="ShelterandFuelService")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetAddresses(ByVal skip As Integer, ByVal take As Integer) As FuelStop()
Dim sqlCon As New SqlConnection
Dim resultList = New List(Of FuelStop)()
Try
sqlCon.ConnectionString = "Data Source=google.watersports.com;Initial Catalog=myDb;Persist Security Info=True;Connect Timeout=30;User ID=****;Password=******"
Dim command As New SqlCommand("SELECT @Physical_Address_Street, @Physical_Address_Local, @Physical_Address_State, @Physical_Address_Zip, @Phone_Number FROM Gas_Stations WHERE Location_Type = 1")
command.Parameters.Add("@Physical_Address_Street", SqlDbType.VarChar, 50).Value = "Physical_Address_Street"
command.Parameters.Add("@Physical_Address_Local", SqlDbType.VarChar, 50).Value = "Physical_Address_Local"
command.Parameters.Add("@Physical_Address_State", SqlDbType.VarChar, 50).Value = "Physical_Address_State"
command.Parameters.Add("@Physical_Address_Zip", SqlDbType.VarChar, 50).Value = "Physical_Address_Zip"
command.Parameters.Add("@Phone_Number", SqlDbType.VarChar, 50).Value = "Phone_Number"
command.Connection = sqlCon
sqlCon.Open()
'command.ExecuteNonQuery()
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)
resultList.Add(fuelStop)
End While
End Using
Catch ex As Exception
sqlCon.Close()
Finally
sqlCon.Close()
End Try
Return resultList.Skip(skip).Take(take).ToArray()
根据下面的 Sql 命令,我可能会返回几百个地址,如何将其合并到我的 vb.net 逻辑中以返回地址列表?
Dim command As New SqlCommand("SELECT Physical_Address_Street, Physical_Address_Local, Physical_Address_State, Physical_Address_Zip, Phone_Number FROM Gas_Stations WHERE Location_Type = 1")
这是我的加油站课程
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
End Class