2013-04-21 48 views
0

我只是想知道如果一個Web服務可以保存我發送給它的字符串,而不需要每次調用WS時重置它。Web服務保存一個函數的字符串值

<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保留值命令如果應用程序只檢查了嗎?

實施例:

我發送爲命令並且由於其不READ它存儲在lcdLevel。一旦Android手機轉到「每5分鐘」檢查,它會讀取或將它什麼都沒有?

我在想,我需要移動Dim lcdLevel As String =「」函數之外,因爲它在每次函數調用的開始?我是否只需要將該函數放在函數的外部以保持存儲的值或者還有其他我還需要做的事情?

謝謝!

+0

並非沒有某種會話管理。 Web服務像普通網頁一樣是無狀態的。 – 2013-04-21 19:16:03

+0

@AdrianGodong多數民衆贊成在我的想法。 – StealthRT 2013-04-21 19:16:35

回答

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中輕鬆存儲值的唯一方法嗎? 似乎工作,因爲我也需要它。

相關問題