KSOAP を使用して Web サービスと通信する Android アプリを作成しています。Web サービスを呼び出して戻り値 (こんにちは) を取得できるため、Web サービスと Android アプリ間の接続は機能しています。しかし、アプリから .addProperty を介して Web サービスに名前を付けようとすると、Web サービスは null オブジェクトを返します。
これが私のコードです:
主な活動:
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();
}
}
ウェブサーバー:
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;
}
}
あなたが私を助けてくれることを願っています!