• 在Android中访问WebService接口


    需要引入ksoap2-android-assembly-2.5.2-jar-with-dependencies.jar

    //WebService的命名空间
    staticfinal String namespace ="http://impl.service.suncreate.com";
    //服务器发布的url
    staticfinal String url = http://10.100.3.41/axis2/services/UploadService;

    final String methodName ="upload"; // 函数名
    finalint sessionID ="111111"; //sessionID

    //创建HttpTransportSE对象,通过HttpTransportSE类的构造方法可以指定WebService的url

    HttpTransportSE transport
    =new HttpTransportSE(url);
    transport.debug
    =true;

    //指定WebService的命名空间和函数名
    SoapObject soapObject =new SoapObject(namespace, methodName);

    //设置调用方法参数的值
    soapObject.addProperty("sessionID", sessionID); //sessionID
    soapObject.addProperty("data", cds); //cds是需要传递的对象

    SoapSerializationEnvelope envelope
    =new SoapSerializationEnvelope(SoapEnvelope.VER10);
    envelope.bodyOut
    = transport;
    envelope.setOutputSoapObject(soapObject);

    //使用call方法调用WebService方法
    transport.call(null, envelope);
    SoapObject sb
    = (SoapObject) envelope.bodyIn;
    String xmlMessage
    = sb.toString(); // 获取从服务器端返回的XML字符串


  • 相关阅读:
    android 和 java 调色板
    BroadCast简述
    android intent
    android intent隐身启动和Intent过滤器
    坦克大战(TankWar)
    android menu
    WAS5.1上LogFactory的错误
    持续加班的夜晚中
    忙,无心写blog
    曾经,我是那么的有激情
  • 原文地址:https://www.cnblogs.com/gzggyy/p/2086161.html
Copyright © 2020-2023  润新知