我在Tomcat 8.5和Axis2在Eclipse這個Web服務類運行:Web服務二傳手不工作
public int volumen = 0, led = 0;
public String ultimaFecha = "null";
public int Volumen() {
return volumen;
}
public String Fecha() {
return LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"));
}
public String Ultima() {
return ultimaFecha;
}
public int LED() {
System.out.println("LED: " + this.led);
return led;
}
public void setLED(int led) {
System.out.println("Old LED: " + this.led);
this.led = led;
System.out.println("New LED: " + this.led);
ultimaFecha = Fecha();
}
當我嘗試調用setLED(int led)
方法,它似乎正常工作,顯示的結果是更新正確,但是當我打電話給getter LED()
時,它會返回初始0值。在C#:
SensorServices.Sensor s = new SensorServices.Sensor();
s.setLED(30);
var result = s.LED();
結果的值是0在Tomcat中,打印的出上述:
Old LED: 0
New LED: 30
LED: 0
這是怎麼回事?爲什麼我無法更新變量的值?我該如何解決這個問題?
您是否使用了'SensorServices.Sensor'的同一個實例? – sidgate
這是不可能的。 '新LED:30'表示值已更改。你在做什麼? – GurV
實例並沒有改變,因爲我從同一個客戶端方法的作用域調用了兩個服務的方法。此外,我還嘗試創建對象的靜態單個實例,但它也無法工作。 Java類如下所示。 –