1 加载jar

下载jar包,放在libs下

通过Project Structure添加jar依赖

成功后就会在build.gradle下添加

代码

    final static String SERVICE_NS = "http://ws.service.mService.et.cn/";    final static String SERVICE_URL = "http://192.168.9.59:8080/DSer/service/SysService?WSDL";    private EditText txt1;    private EditText txt2;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        //注意下面两行        StrictMode.ThreadPolicy policy= new StrictMode.ThreadPolicy.Builder().permitAll().build();        StrictMode.setThreadPolicy(policy);        setContentView(R.layout.activity_cxf);        Button button = findViewById(R.id.cxf_button1);        button.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                //Toast.makeText(CxfActivity.this,"ceshi",Toast.LENGTH_LONG).show();                getCxf();            }        });        txt1 = findViewById(R.id.cxf_EditText1);        txt2 = findViewById(R.id.cxf_EditText2);    }    public void getCxf() {        //调用的方法        String methodName = "getEtUser";        //创建httpTransportSE传输对象        HttpTransportSE ht = new HttpTransportSE(SERVICE_URL);        ht.debug = true;        //使用soap1.1协议创建Envelop对象        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);        //实例化SoapObject对象        SoapObject request = new SoapObject(SERVICE_NS, methodName);        /**         * 设置参数,参数名不一定需要跟调用的服务器端的参数名相同,只需要对应的顺序相同即可         * */        request.addProperty("userName", "000");        //将SoapObject对象设置为SoapSerializationEnvelope对象的传出SOAP消息        envelope.bodyOut = request;        try{            //调用webService            ht.call(null, envelope);            //txt1.setText("看看"+envelope.getResponse());            if(envelope.getResponse() != null){                txt2.setText("有返回");                SoapObject result = (SoapObject) envelope.bodyIn;                SoapObject soap = (SoapObject) result.getProperty(0); //这个例子是返回一个对象。                String name =soap.getProperty("name").toString();                String userName =soap.getProperty("userName").toString();                String department =soap.getProperty("department").toString();                txt1.setText("返回值 = "+ name+ " "+userName + " " +department);            }else{                txt2.setText("无返回");            }        }catch (Exception e) {            e.printStackTrace();        }    }

AndroidManifest.xml

AndroidManifest.xml下添加

更多相关文章

  1. 类和 Json对象
  2. Android(安卓)sd卡读取数据库实例代码
  3. cocos2d-x eclipse android 配置注意项(笔记)
  4. Android(安卓)实现闪屏页和右上角的倒计时跳转
  5. Ecliplse中开发android中使用单元测试注意
  6. Android的ListView,数据更新后自动scroll到底部。
  7. android 一直在最前面的浮动窗口效果
  8. android Activity单元测试
  9. JsonObject和Gson详解

随机推荐

  1. arcgis for android 离线切片加载与geoda
  2. Android:如何实现例如iOS的listview 的弹
  3. [Android] 启动无线与网络设置的Action__
  4. 2011.12.06——— android 带边框的Image
  5. Android 默认把触摸屏show touches打开
  6. Android 9.0 (P版本) SystemServer中的服
  7. android中设置控件获得焦点
  8. Android(安卓)RecyclerView更新删除单条
  9. [意见反馈][官方博客]
  10. Android 存储方式之文件存储