我是 servicestack.net 的新手,我正在努力访问我的方法中的标头信息。我附上了我正在使用的代码。它在 vb.net
服务栈类 a)服务栈请求类
Public Class LeaveManagementDashboardRequest
Public Property ClientID As String
Public Property DateFormatID As String
Public Property UserID As String
Public Property NOOFROWS As String
End Class
b)服务栈响应类
Public Class LeaveManagementDashboardResponse
Public Property data As String
End Class
c)Service Stack 服务类(实际服务实现)
Public Class LeaveManagementDashboardService
Implements IService(Of LeaveManagementDashboardRequest)
Private sqlCon As New SqlConnection
Public Function Execute(ByVal request As LeaveManagementDashboardRequest) As Object Implements ServiceStack.ServiceHost.IService(Of LeaveManagementDashboardRequest).Execute
Dim ds As New DataSet
If sqlcon.State = ConnectionState.Closed Then
Common.OpenConnection(sqlCon)
End If
Dim ClientID As String = request.ClientID
Dim UserID As String = request.UserID
Dim DataFormatID As String = request.DateFormatID
Dim NOOFROWS As String = request.NOOFROWS
Dim sqlcmd As New SqlCommand("abcdefg", sqlcon)
sqlcmd.CommandType = CommandType.StoredProcedure
sqlcmd.Parameters.Add(New SqlParameter("@UserID", SqlDbType.Int, 0))
sqlcmd.Parameters.Add(New SqlParameter("@DateFormatID", SqlDbType.TinyInt, 0))
sqlcmd.Parameters.Add(New SqlParameter("@Count", SqlDbType.SmallInt, 0))
sqlcmd.Parameters.Add(New SqlParameter("@ClientID", SqlDbType.Int, 0))
sqlcmd.Parameters(0).Value = UserID
sqlcmd.Parameters(1).Value = DataFormatID
sqlcmd.Parameters(2).Value = NOOFROWS
sqlcmd.Parameters(3).Value = ClientID
Dim dsResult As New DataSet
Dim sqlda As New SqlDataAdapter(sqlcmd)
sqlda.Fill(dsResult)
Dim obj As String = Common.GetJson(dsResult.Tables(0))
' obj.countries = lstCountries
sqlcon.Close()
sqlcon.Dispose()
Return New LeaveManagementDashboardResponse With {.data = obj}
Return dsResult
End Function
End Class
路由在 Global.aspx.cs 文件中定义,如下所示
Public Class _Global
Inherits System.Web.HttpApplication
Public Class HelloAppHost
Inherits AppHostBase
Public Sub New()
MyBase.New("Plant Best Services", GetType(HelloAppHost).Assembly)
End Sub
Public Overrides Sub Configure(ByVal container As Container)
Routes.Add(Of LeaveManagementDashboardRequest)("/pml/Dashboard/LeavesRequests")
End Sub
End Class
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim apphost = New HelloAppHost()
apphost.Init()
End Sub