android访问webservice

来源:互联网 发布:手机上怎么注册淘宝店 编辑:程序博客网 时间:2024/04/24 02:57
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();            }

0 0