您的位置:首页 > 移动开发 > Android开发

android访问webservice

2014-05-07 21:58 253 查看
new AsyncTask<String, Integer, String>() {

@Override
protected String doInBackground(String... params) {
String namespace = "http://tempuri.org/";
//String namespace = "http://www.jskfhn.org.cn/";
String url = "http://www.jskfhn.org.cn/CallCenterWebService/Interface/AppointmentService.asmx";
//String method = "GetAllHospital";
String method = "Init";
String action = namespace+method;
SoapObject soap = new SoapObject(namespace, method);
//soap.addProperty(name, value); //设置参数

SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11);
env.bodyOut = soap;
env.dotNet = true;
//env.setOutputSoapObject(soap);

HttpTransportSE trans = new HttpTransportSE(url);
trans.debug = true;
try {
trans.call(action, env);
if (env.getResponse() != null) {
// 获取服务器响应返回的SOAP消息
SoapObject result = (SoapObject) env.bodyIn;
Object detail = result.getProperty(method
+ "Result");
//SoapObject detail = (SoapObject)env.bodyIn;
// 解析服务器响应的SOAP消息
return detail.toString()  ;
}
/* SoapObject object = (SoapObject)env.getResponse();
Log.i("result", object.toString());*/
} catch (HttpResponseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
return null;
}

/* (non-Javadoc)
* @see android.os.AsyncTask#onPostExecute(java.lang.Object)
*/
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub

System.out.println("返回的结果:"+result);
}

}.execute();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: