我正在使用ksoap2-android
庫從Android應用程序調用java web服務。使用ksoap2從Android調用java web服務:參數全爲空
問題是,雖然我請求的方法實際上是正確調用的,但它的所有參數(都是簡單字符串)始終是null
!
這裏是我的代碼:
JAX-WS Web服務:
@WebService(targetNamespace="webservices.delta.elia.unipd")
public class DeltaUploadService {
@WebMethod(operationName = "uploadLogData")
public boolean uploadLogData(String deviceID, String experimentID, String filename, String data){
System.out.println("Incoming data from device: " + deviceID + ", Experiment ID: " + experimentID);
//All the parameters here are NULL!
}
}
的Android代碼:
public static boolean uploadLog(String deviceID, String experimentID, String filename, String serverUrl, byte[] data){
String NAMESPACE = "webservices.delta.elia.unipd";
String SOAP_ACTION = "webservices.delta.elia.unipd/uploadLogData";
// Create request
SoapObject request = new SoapObject(NAMESPACE, "uploadLogData");
//add parameters
request.addProperty("deviceID", deviceID);
request.addProperty("experimentID", experimentID);
request.addProperty("filename", filename);
request.addProperty("data", Base64.encodeToString(data, Base64.DEFAULT));
// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(serverUrl);
try {
// Invoke web service
androidHttpTransport.call(SOAP_ACTION, envelope);
// Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
return Boolean.parseBoolean(response.toString());
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
我在做什麼錯? PS:我用SoapUI工具測試了java web服務,它工作正常,所以問題必須在ksoap2庫或我的Android代碼中。
重要通知:我已閱讀其他答案,如ksoap2 - request parameters is set null和KSoap calling .NET ASMX service passing null arguments但他們沒有幫助。