0
我正在編寫一個Android應用程序,使用KSOAP與Web服務進行通信。 Web服務和Android應用程序之間的連接正在工作,因爲我可以調用web服務並獲取返回值(hello)。但是,如果我嘗試通過.addProperty將應用程序名稱提供給Web服務,則Web服務將返回一個空對象。從Android應用程序調用Web服務返回空對象
這裏是我的代碼:
MainActivity:
private final String NAMESPACE_Local = "http://test.com/";
private final String URL_Local = "http://168.185.226.21:7001/myTest/myTestWebServiceService";
private final String SOAP_ACTION_Local = "Hello_Action_Extend";
private final String METHOD_NAME_Local = "hello_extend";
public void LocalServer(View view)
{
TextView text = (TextView) findViewById(R.id.update_text);
SoapObject request = new SoapObject(NAMESPACE_Local, METHOD_NAME_Local);
request.addProperty("name", "Christian");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL_Local);
try {
androidHttpTransport.call(SOAP_ACTION_Local, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.i("myApp", response.toString());
text.setText(response.toString());
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this,"Device or service offline",Toast.LENGTH_LONG).show();
}
}
的WebServer:
package com.test;
import javax.jws.*;
@WebService
public class myTestWebService {
@WebMethod(action="Hello_Action") //that method works
public String hello() {
return "hello";
}
@WebMethod(action="Hello_Action_Extend")
public String hello_extend(String name) //that works also, but it is giving back "hello null"
{
return "hello "+name;
}
}
我希望你能幫幫我!
嘿,感謝您的回答。不幸的是,Eclipse會給你的每個建議提供錯誤。對於request.addProperty(「name」,ElementType.STRING_CLASS,「Christian」);是說STRING_CLASS無法解析或不是一個字段....對於第二個response.getProperty(「名稱」); Eclipse希望將響應強制轉換爲SoapObject或KvmSerializable,但都不起作用。 – chrissik 2013-03-06 06:41:54