android="
xmlns:
tools="
android:
layout_width="fill_parent"
android:
layout_height="fill_parent">
android:
id="@+id/tableLayout1"
android:
layout_width="wrap_content"
android:
layout_height="wrap_content">
packagecom.example.testwcf;
importorg.apache.http.HttpResponse;
importorg.apache.http.client.HttpClient;
importorg.apache.http.client.methods.HttpGet;
importorg.apache.http.client.methods.HttpPost;
importorg.apache.http.entity.StringEntity;
importorg.apache.http.impl.client.DefaultHttpClient;
importorg.apache.http.protocol.HTTP;
importorg.apache.http.util.EntityUtils;
importorg.json.JSONObject;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.view.Menu;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.Toast;
publicclassMainActivityextendsActivity{
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
{
Buttonbutton=(Button)super
.findViewById(R.id.btnGetAccountDataByGet);
button.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
try{
HttpClientclient=newDefaultHttpClient();
HttpGetrequest=newHttpGet(
"http:
//10.168.1.102:
9999/IAccountRestService/GetAccountDataByGet");
HttpResponseresponse=client.execute(request);
Toast.makeText(MainActivity.this,
EntityUtils.toString(response.getEntity()),
Toast.LENGTH_SHORT).show();
}catch(Exceptione){
e.printStackTrace();
}
}
});
}
{
Buttonbutton=(Button)super
.findViewById(R.id.btnGetAccountDataByPost);
button.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
try{
HttpClientclient=newDefaultHttpClient();
HttpPostrequest=newHttpPost(
"http:
//10.168.1.102:
9999/IAccountRestService/GetAccountDataByPost");
HttpResponseresponse=client.execute(request);
Toast.makeText(MainActivity.this,
EntityUtils.toString(response.getEntity()),
Toast.LENGTH_SHORT).show();
}catch(Exceptione){
e.printStackTrace();
}
}
});
}
{
Buttonbutton=(Button)super
.findViewById(R.id.btnSendMessageByGet1);
button.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
try{
HttpClientclient=newDefaultHttpClient();
HttpGetrequest=newHttpGet(
"http:
//10.168.1.102:
9999/IAccountRestService/SendMessageByGet1?
message=aaa&value=3");
HttpResponseresponse=client.execute(request);
Toast.makeText(MainActivity.this,
EntityUtils.toString(response.getEntity()),
Toast.LENGTH_SHORT).show();
}catch(Exceptione){
e.printStackTrace();
}
}
});
}
{
Buttonbutton=(Button)super
.findViewById(R.id.btnSendMessageByGet2);
button.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
try{
HttpClientclient=newDefaultHttpClient();
HttpGetrequest=newHttpGet(
"http:
//10.168.1.102:
9999/IAccountRestService/SendMessageByGet2/bbb/4");
HttpResponseresponse=client.execute(request);
Toast.makeText(MainActivity.this,
EntityUtils.toString(response.getEntity()),
Toast.LENGTH_SHORT).show();
}catch(Exceptione){
e.printStackTrace();
}
}
});
}
{
Buttonbutton=(Button)super
.findViewById(R.id.btnSendMessageByPost1);
button.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
try{
HttpClientclient=newDefaultHttpClient();
HttpPostrequest=newHttpPost(
"http:
//10.168.1.102:
9999/IAccountRestService/SendMessageByPost1");
JSONObjectp=newJSONObject();
p.put("value",4);
p.put("message","ccc");
request.setEntity(newStringEntity(p.toString()));
request.setHeader(HTTP.CONTENT_TYPE,"text/json");
HttpResponseresponse=client.execute(request);
Stringre=EntityUtils.toString(response.getEntity());
Toast.makeText(MainActivity.this,re,
Toast.LENGTH_SHORT).show();
}catch(Exceptione){
e.printStackTrace();
}
}
});
}
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
getMenuInflater().inflate(R.menu.activity_main,menu);
returntrue;
}
}