0

我只是想知道 Web 服务是否可以将我发送给它的内容保存为字符串,而无需在每次调用 WS 时都重置它?

<WebMethod()> _
Public Function sendLCDBrightnessLevel(ByRef command As String) As String
    'This reads a number for the LCD brightness level and store it
    'The phone will call this function every 5 minutes to see what the value is
    'android phone->WS
    Dim lcdLevel As String = ""

    If command <> "READ" Then
        lcdLevel = command
        Return "Stored: " & lcdLevel
    Else
        Return lcdLevel
    End If
End Function

如果应用程序只是检查它,lcdLevel会保留命令中的值吗?

例子:

我为命令发送30并且由于它不是READ它将它存储在lcdLevel中。一旦 Android 手机进行“每 5 分钟”检查,它会读取30还是什么都没有?

我在想我需要将Dim lcdLevel As String = ""移到函数之外,因为它每次都在函数调用的开头?我是否只需将其放在函数之外以保持存储的值,还是我还需要做其他事情?

谢谢!

4

1 回答 1

0
<WebMethod()> _
Public Function sendLCDBrightnessLevel(ByRef command As String) As String
    'This reads a number for the LCD brightness level and store it
    'The phone will call this function every 5 minutes to see what the value is
    'android phone->WS
    Dim lcdLevel As String = ""
    Dim path As String = "c:\temp\lcdValue.txt"

    If command <> "READ" Then
        lcdLevel = command
        Dim objWriter As New System.IO.StreamWriter(path, False, Encoding.UTF8)

        objWriter.WriteLine(lcdLevel)
        objWriter.Close()

        Return "Stored: " & lcdLevel
    Else
        Dim objReader As New System.IO.StreamReader(path, Encoding.UTF8)

        lcdLevel = objReader.ReadToEnd
        objReader.Close()

        Return lcdLevel
    End If
End Function

猜猜这是在 WS 中轻松存储值的唯一方法吗?似乎也可以按我的需要工作。

于 2013-04-21T19:27:26.377 回答