안드로이드용 ksoap2 다운 받기
http://code.google.com/p/ksoap2-android/
http://code.google.com/p/ksoap2-android/wiki/HowToUse
ksoap2를 안드로이드 프로젝트에서 External JARs 로 추가.
[ main.java]
package com.its.hanium;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class main extends Activity
{
Button mButton_methodA;
Button mButton_methodB;
Button mButton_methodHelloWorld;
EditText mEdit_debugConsole;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//connect View
mButton_methodA=(Button)findViewById(R.id.button_methodA);
mButton_methodB=(Button)findViewById(R.id.button_methodB);
mButton_methodHelloWorld=(Button)findViewById(R.id.button_methodHelloWorld);
mEdit_debugConsole=(EditText)findViewById(R.id.edit_debugConsole);
//OCL
mButton_methodA.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String result=call_serverMethodA(40);
print(result);
} //onClick
}); //methodA OCL
mButton_methodB.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String result=call_serverMethodB("dldldl", 555);
print(result);
} //void onClick
}); //methodB OCL
mButton_methodHelloWorld.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String result=call_serverMethodHelloWorld();
print(result);
} //void onClick
}); //methodHelloWorld OCL
} //void onCreate
private String call_serverMethodA(int arg1)
{
return new adapterServer().method_A(arg1);
} //String call_serverMethodA
private String call_serverMethodB(String arg1, int arg2)
{
return new adapterServer().method_B(arg1, arg2);
} //String call_serverMethodB
private String call_serverMethodHelloWorld()
{
return new adapterServer().method_HelloWorld();
} //String call_serverMethodHelloWorld
private void print(String str)
{
mEdit_debugConsole.setText( mEdit_debugConsole.getText() + str );
} //void debug
} //class main
[ adapterServer.java ]
package com.its.hanium;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.util.Log;
public class adapterServer
{
private String soapAction="http://tempuri.org/"; //"http://tempuri.org/forTest";
private String methodName="forTest";
private String namespace="http://tempuri.org/"; //"http://tempuri.org/";
private final String URL="http://192.168.2.100:80/webServiceTest/WebService.asmx";
private String request(SoapObject request)
{
SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet=true;
AndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(URL);
//System.out.println(request); //confirm parameter
Log.d("ITS.Hanium", "confirm parameter : " + request);
try
{
androidHttpTransport.call(soapAction, envelope);
String result=envelope.getResponse().toString();
//System.out.println(result);
Log.d("ITS.Hanium", "request finished. the result : " + result);
return result;
} catch(Exception e)
{
e.printStackTrace();
return e.getLocalizedMessage();
} //try-catch
} //String sendRequest
public String method_A(int par1)
{
Log.d("ITS.Hanium", "adapterServer.method_A called. parameter : " + String.valueOf(par1));
methodName="method_A";
soapAction="http://tempuri.org/" + methodName;
SoapObject request=new SoapObject(namespace, methodName);
request.addProperty("parameter", par1);
String result=request(request);
return result;
} //String method_A
public String method_B(String par1, int par2)
{
Log.d("ITS.Hanium", "adapterServer.method_A called. parameter : " + par1 + " / " + String.valueOf(par2));
methodName="method_B";
soapAction="http://tempuri.org/" + methodName;
SoapObject request=new SoapObject(namespace, methodName);
request.addProperty("par1", par1);
request.addProperty("par2", par2);
String result=request(request);
return result;
} //String method_B
public String method_HelloWorld()
{
Log.d("ITS.Hanium", "adapterServer.method_HelloWorld called. There're no parameter");
methodName="HelloWorld";
soapAction="http://tempuri.org/" + methodName;
SoapObject request=new SoapObject(namespace, methodName);
String result=request(request);
return result;
} //String method_HelloWorld
} //class adapter_server
Android Sound Code (0) | 2018.01.05 |
---|---|
간단한 웹 브라우저 (0) | 2012.04.25 |
WebView 를 사용할때 HttpClient 를 이용한 Session 유지 (0) | 2012.02.16 |
안드로이드 세션연구 (0) | 2012.02.16 |
구글 마켓에 앱 올리기 (0) | 2012.01.28 |