現在、私はメソッドSOAPによってAndroidからWebサービスを利用しています。ここでWebサービスを呼び出し、android / eclipse.ieに結果を返す必要があります。edittextから入力を取得し、適切な値を返す必要があります。
参考のために私のコードを見つけてください。
ウェブメソッド
public class GetName {
public String GetName(String a){
return(a);
} }
注: メインアクティビティスレッドからのソケット操作の例外を回避するために、別のクラスを作成し、soap関連の関数を分離しました。
Caller.java
public class Caller extends Thread
{
public AlertDialog ad;
public CallSoap cs;
public int a;
public void run()
{
try
{
cs=new CallSoap();
String resp=cs.Call(a);
MySOAPCallActivity.rslt=resp;
}catch(Exception ex)
{
MySOAPCallActivity.rslt=ex.toString();
}
} }
CallSOAP
public class CallSoap
{
public final String SOAP_ACTION = "http://tempuri.org/GetName";
public final String OPERATION_NAME = "GetName";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://122.248.240.105:234/Service1.asmx?WSDL";
public CallSoap()
{
}
public String Call(int a)
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();
pi.setName("a");
pi.setValue(a);
pi.setType(Integer.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response=null;
try
{
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
}
catch (Exception exception)
{
response=exception.toString();
}
return response.toString();
}
}
MySOAPCallActivity
public class MySOAPCallActivity extends Activity
{
public static String rslt="";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b1=(Button)findViewById(R.id.btn_getvalues);
final AlertDialog ad=new AlertDialog.Builder(this).create();
b1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
try
{
EditText ed1=(EditText)findViewById(R.id.et_1);
String ed1str = ed1.getText().toString().trim();
int a = Integer.parseInt(ed1str);
rslt="START";
Caller c=new Caller();
c.a=a;
c.ad=ad;
c.join();
c.start();
while(rslt=="START")
{
try
{
Thread.sleep(5);
}catch(Exception ex)
{
}
}
ad.setTitle("");
ad.setMessage(rslt);
}catch(Exception ex)
{
ad.setTitle("Error!");
ad.setMessage(ex.toString());
}
ad.show();
}
});
} }
出力画面
注: vlaue "0005"を入力すると、ブラウザに文字列"Vivek"が返される必要があります。
しかし、出力画面に「名前が見つかりません」と表示されます。ユーザーの入力に従って適切な値を返したいのですが、ソースを修正する方法を教えてください。
貴重なお時間をいただきありがとうございます!..