c# webservice 怎么接收android发送的http的post请求
1个回答
展开全部
String rs="";
try {
final String SERVER_URL = "http://127.0.0.1/service.asmx";
String nameSpace = "http://tempuri.org/";//命名空间
String methodName = "HelloWorld";//方法名
String soapAction = "http://tempuri.org/HelloWorld";//HelloWorld 命名空间/方法名
//创建SoapObject实例
SoapObject request = new SoapObject(nameSpace, methodName);
request.addProperty("name",gpp);
request.addProperty("jd",gpp2);
rs="到这里了";
//生成调用web service方法的soap请求消息
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true; //设置.net web service
envelope.setOutputSoapObject(request);//发送请求
rs="到这里了2";
HttpTransportSE androidHttpTransport = new HttpTransportSE(SERVER_URL);
rs="到这里了3";
androidHttpTransport.call(soapAction, envelope);
rs="到这里了4";
Object result = (Object) envelope.getResponse();
//textView.setText(e.getMessage());
return result.toString();
//textView.setText("7");
// new AlertDialog.Builder(this).setTitle("Hint").setMessage(result.toString()).setPositiveButton("OK", null).show();
}
catch (Exception e)
{
System.out.println(e.getMessage());
// textView.setText(e.getMessage());
// new AlertDialog.Builder(this).setTitle("Hint").setMessage(e.getMessage()).setPositiveButton("OK", null).show();
}
return rs;
}
@Override
protected void onProgressUpdate(Integer... progress) {
//这个函数在doInBackground调用publishProgress时触发,虽然调用时只有一个参数
//但是这里取到的是一个数组,所以要用progesss[0]来取值
//第n个参数就用progress[n]来取值
tv.setText(progress[0]+"%");
super.onProgressUpdate(progress);
}
@Override
protected void onPostExecute(String result) {
//doInBackground返回时触发,换句话说,就是doInBackground执行完后触发
//这里的result就是上面doInBackground执行后的返回值,所以这里是"执行完毕"
setTitle(result);
tv.setText(result);
super.onPostExecute(result);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
这是我做的参考下
try {
final String SERVER_URL = "http://127.0.0.1/service.asmx";
String nameSpace = "http://tempuri.org/";//命名空间
String methodName = "HelloWorld";//方法名
String soapAction = "http://tempuri.org/HelloWorld";//HelloWorld 命名空间/方法名
//创建SoapObject实例
SoapObject request = new SoapObject(nameSpace, methodName);
request.addProperty("name",gpp);
request.addProperty("jd",gpp2);
rs="到这里了";
//生成调用web service方法的soap请求消息
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true; //设置.net web service
envelope.setOutputSoapObject(request);//发送请求
rs="到这里了2";
HttpTransportSE androidHttpTransport = new HttpTransportSE(SERVER_URL);
rs="到这里了3";
androidHttpTransport.call(soapAction, envelope);
rs="到这里了4";
Object result = (Object) envelope.getResponse();
//textView.setText(e.getMessage());
return result.toString();
//textView.setText("7");
// new AlertDialog.Builder(this).setTitle("Hint").setMessage(result.toString()).setPositiveButton("OK", null).show();
}
catch (Exception e)
{
System.out.println(e.getMessage());
// textView.setText(e.getMessage());
// new AlertDialog.Builder(this).setTitle("Hint").setMessage(e.getMessage()).setPositiveButton("OK", null).show();
}
return rs;
}
@Override
protected void onProgressUpdate(Integer... progress) {
//这个函数在doInBackground调用publishProgress时触发,虽然调用时只有一个参数
//但是这里取到的是一个数组,所以要用progesss[0]来取值
//第n个参数就用progress[n]来取值
tv.setText(progress[0]+"%");
super.onProgressUpdate(progress);
}
@Override
protected void onPostExecute(String result) {
//doInBackground返回时触发,换句话说,就是doInBackground执行完后触发
//这里的result就是上面doInBackground执行后的返回值,所以这里是"执行完毕"
setTitle(result);
tv.setText(result);
super.onPostExecute(result);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
这是我做的参考下
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询