62,046
社区成员
发帖
与我相关
我的任务
分享
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
'若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class _001_wssReturnString
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld() As String
Return "<hello>Hello World</hello>"
'结果:
'<?xml version="1.0" encoding="utf-8"?>
'<string xmlns="http://tempuri.org/"><hello>Hello World</hello></string>
End Function
<WebMethod()> _
Public Function GetInteger() As Integer
Dim index As Integer = 100
Return index
'<?xml version="1.0" encoding="utf-8" ?>
'<int xmlns="http://tempuri.org/">100</int>
End Function
<WebMethod()> _
Public Function GetDouble() As Double
Dim d As Double = 10.2
Return d
'<?xml version="1.0" encoding="utf-8" ?>
'<double xmlns="http://tempuri.org/">10.2</double>
End Function
<WebMethod()> _
Public Function GetEmployee() As Employee
Dim emp As New Employee
emp.FirstName = "Bill"
emp.LastName = "Gates"
emp.Salary = 100000000
Return emp
'结果:
'<?xml version="1.0" encoding="utf-8"?>
'<Employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
' <FirstName>Bill</FirstName>
' <LastName>Gates</LastName>
' <Salary>100000000</Salary>
'</Employee>
End Function
<WebMethod()> _
Public Function GetEmployees() As List(Of Employee)
Dim emp1 As New Employee
emp1.FirstName = "Bill"
emp1.LastName = "Gates"
emp1.Salary = 100000000
Dim emp2 As New Employee
emp2.FirstName = "Barack"
emp2.LastName = "Obama"
emp2.Salary = 20000000
Dim empList As New List(Of Employee)
empList.Add(emp1)
empList.Add(emp2)
Return empList
'<?xml version="1.0" encoding="utf-8"?>
'<ArrayOfEmployee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
' <Employee>
' <FirstName>Bill</FirstName>
' <LastName>Gates</LastName>
' <Salary>100000000</Salary>
' </Employee>
' <Employee>
' <FirstName>Barack</FirstName>
' <LastName>Obama</LastName>
' <Salary>20000000</Salary>
' </Employee>
'</ArrayOfEmployee>
End Function
<WebMethod()> _
Public Function GetDataSet() As DataSet
Dim ds As New DataSet
ds.Tables.Add(_GetDataTable)
Return ds
End Function
Public Function _GetDataTable() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("Index", GetType(Integer)))
dt.Columns.Add(New DataColumn("Name", GetType(String)))
dt.Columns.Add(New DataColumn("Value", GetType(String)))
Dim dr As DataRow
For i As Integer = 0 To 10
dr = dt.NewRow()
dr("Index") = i
dr("Name") = "Name " + i.ToString
dr("Value") = "Value " + i.ToString
dt.Rows.Add(dr)
Next
Return dt
End Function
End Class
Public Class Employee
Private _FirstName As String
Public Property FirstName() As String
Get
Return _FirstName
End Get
Set(ByVal value As String)
_FirstName = value
End Set
End Property
Private _LastName As String
Public Property LastName() As String
Get
Return _LastName
End Get
Set(ByVal value As String)
_LastName = value
End Set
End Property
Private _salary As Double
Public Property Salary() As Double
Get
Return _salary
End Get
Set(ByVal value As Double)
_salary = value
End Set
End Property
End Class