Search in sources :

Example 1 with SoapObject

use of org.ksoap2.serialization.SoapObject in project teaTime by ancfdy.

the class WebServiceUtils method callWebService.

/**
 *请求网络数据
 * @param url
 *            WebService服务器地址
 * @param methodName
 *            WebService的调用方法名
 * @param properties
 *            WebService的参数
 * @param webServiceCallBack
 *            回调接口
 */
public static void callWebService(String url, final String methodName, HashMap<String, String> properties, final WebServiceCallBack webServiceCallBack) {
    // 创建HttpTransportSE对象,传递WebService服务器地址
    final HttpTransportSE httpTransportSE = new HttpTransportSE(url);
    // 创建SoapObject对象
    SoapObject soapObject = new SoapObject(NAMESPACE, methodName);
    if (properties != null) {
        for (Iterator<Entry<String, String>> it = properties.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry<String, String> entry = it.next();
            soapObject.addProperty(entry.getKey(), entry.getValue());
        }
    }
    // 实例化SoapSerializationEnvelope,传入WebService的SOAP协议的版本号
    // tomcat 7.055 for 64  jdk 1.6 for 64  web3.0 这里写 ver12 ,如果是ver11会报 http 415错误
    final SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
    // 设置是否调用的是.Net开发的WebService
    soapEnvelope.bodyOut = soapObject;
    // 如果调用的是.Net的WebService,这里为true,否则为false,不然调用会不成功
    soapEnvelope.dotNet = false;
    soapEnvelope.setOutputSoapObject(soapObject);
    httpTransportSE.debug = true;
    // 用于子线程与主线程通信的Handler
    final Handler mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            // 将返回值回调到callBack的参数中
            webServiceCallBack.callBack((Object) msg.obj);
        }
    };
    // 开启线程去访问WebService
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            Object resultSoapObject = null;
            try {
                httpTransportSE.call(WEB_SERVER_URL + methodName, soapEnvelope);
                if (soapEnvelope.getResponse() != null) {
                    // 获取服务器响应返回的SoapObject
                    resultSoapObject = (Object) soapEnvelope.bodyOut;
                }
            } catch (HttpResponseException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                e.printStackTrace();
            } finally {
                // 将获取的消息利用Handler发送到主线程
                mHandler.sendMessage(mHandler.obtainMessage(0, resultSoapObject));
            }
        }
    });
}
Also used : Message(android.os.Message) SoapObject(org.ksoap2.serialization.SoapObject) Handler(android.os.Handler) HttpResponseException(org.ksoap2.transport.HttpResponseException) HttpTransportSE(org.ksoap2.transport.HttpTransportSE) IOException(java.io.IOException) Entry(java.util.Map.Entry) SoapObject(org.ksoap2.serialization.SoapObject) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) SoapSerializationEnvelope(org.ksoap2.serialization.SoapSerializationEnvelope) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with SoapObject

use of org.ksoap2.serialization.SoapObject in project teaTime by ancfdy.

the class WebServiceUtils method callWebService.

/**
 *请求网络数据
 * @param url
 *            WebService服务器地址
 * @param methodName
 *            WebService的调用方法名
 * @param properties
 *            WebService的参数
 * @param webServiceCallBack
 *            回调接口
 */
public static void callWebService(String url, final String methodName, HashMap<String, String> properties, final WebServiceCallBack webServiceCallBack) {
    // 创建HttpTransportSE对象,传递WebService服务器地址
    final HttpTransportSE httpTransportSE = new HttpTransportSE(url);
    // 创建SoapObject对象
    SoapObject soapObject = new SoapObject(NAMESPACE, methodName);
    if (properties != null) {
        for (Iterator<Entry<String, String>> it = properties.entrySet().iterator(); it.hasNext(); ) {
            Entry<String, String> entry = it.next();
            soapObject.addProperty(entry.getKey(), entry.getValue());
        }
    }
    // 实例化SoapSerializationEnvelope,传入WebService的SOAP协议的版本号
    // tomcat 7.055 for 64  jdk 1.6 for 64  web3.0 这里写 ver12 ,如果是ver11会报 http 415错误
    final SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
    // 设置是否调用的是.Net开发的WebService
    soapEnvelope.bodyOut = soapObject;
    // 如果调用的是.Net的WebService,这里为true,否则为false,不然调用会不成功
    soapEnvelope.dotNet = false;
    soapEnvelope.setOutputSoapObject(soapObject);
    httpTransportSE.debug = true;
    // 用于子线程与主线程通信的Handler
    final Handler mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            // 将返回值回调到callBack的参数中
            webServiceCallBack.callBack((Object) msg.obj);
        }
    };
    // 开启线程去访问WebService
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            Object resultSoapObject = null;
            try {
                httpTransportSE.call(WEB_SERVER_URL + methodName, soapEnvelope);
                if (soapEnvelope.getResponse() != null) {
                    // 获取服务器响应返回的SoapObject
                    resultSoapObject = (Object) soapEnvelope.bodyOut;
                }
            } catch (HttpResponseException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                e.printStackTrace();
            } finally {
                // 将获取的消息利用Handler发送到主线程
                mHandler.sendMessage(mHandler.obtainMessage(0, resultSoapObject));
            }
        }
    });
}
Also used : Message(android.os.Message) SoapObject(org.ksoap2.serialization.SoapObject) Handler(android.os.Handler) HttpResponseException(org.ksoap2.transport.HttpResponseException) HttpTransportSE(org.ksoap2.transport.HttpTransportSE) IOException(java.io.IOException) Entry(java.util.Map.Entry) SoapObject(org.ksoap2.serialization.SoapObject) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) SoapSerializationEnvelope(org.ksoap2.serialization.SoapSerializationEnvelope)

Example 3 with SoapObject

use of org.ksoap2.serialization.SoapObject in project SeaStar by 13120241790.

the class SoapManager method getSoapresult.

/**
 * 将SoapObject转json字符串
 * @param soapresult SoapObject
 * @param jsonResult JSONObject
 */
private void getSoapresult(SoapObject soapresult, JSONObject jsonResult, HashSet<String> hashset) {
    try {
        if (soapresult != null) {
            PropertyInfo proinfo = null;
            SoapObject childsoap = null;
            JSONObject childJson = null;
            String curName = null;
            int count = soapresult.getPropertyCount();
            for (int i = 0; i < count; i++) {
                // 获取当前节点的信息
                proinfo = new PropertyInfo();
                soapresult.getPropertyInfo(i, proinfo);
                curName = proinfo.getName();
                // 判断当前节点的类型,如果是SoapPrimitive则可以直接取值,如果是SoapObject则继续解析
                if (SoapPrimitive.class == proinfo.getType()) {
                    jsonResult.put(curName, proinfo.getValue());
                } else if (SoapObject.class == proinfo.getType()) {
                    childJson = new JSONObject();
                    childsoap = (SoapObject) soapresult.getProperty(i);
                    // 判断该节点下面有相同节点,那么他就是一个数组
                    if (isArrayNode(childsoap)) {
                        hashset.add(curName);
                        NLog.e(tag, "curName : " + curName);
                    }
                    // 处理相同名字的节点,到时候好替换成JSONArray
                    if (jsonResult.has(curName)) {
                        curName = curName + i;
                    }
                    // 递归调用自己,获取子节点
                    getSoapresult(childsoap, childJson, hashset);
                    // 将子节点添加到根节点下面
                    jsonResult.put(curName, childJson);
                }
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(org.json.JSONObject) SoapObject(org.ksoap2.serialization.SoapObject) JSONException(org.json.JSONException) PropertyInfo(org.ksoap2.serialization.PropertyInfo)

Example 4 with SoapObject

use of org.ksoap2.serialization.SoapObject in project SeaStar by 13120241790.

the class SoapManager method isArrayNode.

/**
 * 判断该节点下面是否有相同的节点,如果说明是数组
 * @param childsoap
 * @return
 */
public boolean isArrayNode(SoapObject childsoap) {
    PropertyInfo proinfo = null;
    int count = childsoap.getPropertyCount();
    for (int i = 0; i < count; i++) {
        proinfo = new PropertyInfo();
        childsoap.getPropertyInfo(i, proinfo);
        if (SoapObject.class == proinfo.getType()) {
            if (childsoap.hasProperty(proinfo.getName())) {
                return true;
            }
        }
    }
    return false;
}
Also used : PropertyInfo(org.ksoap2.serialization.PropertyInfo)

Example 5 with SoapObject

use of org.ksoap2.serialization.SoapObject in project ETSMobile-Android2 by ApplETS.

the class WebServiceSoap method GetFiche.

public String GetFiche(final String numero, final String PathFiche) throws Exception {
    return (String) execute(new IWcfMethod() {

        @Override
        public ExtendedSoapSerializationEnvelope CreateSoapEnvelope() {
            ExtendedSoapSerializationEnvelope __envelope = createEnvelope();
            SoapObject __soapReq = new SoapObject("http://etsmtl.ca/", "GetFiche");
            __envelope.setOutputSoapObject(__soapReq);
            PropertyInfo __info = null;
            __info = new PropertyInfo();
            __info.namespace = "http://etsmtl.ca/";
            __info.name = "numero";
            __info.type = PropertyInfo.STRING_CLASS;
            __info.setValue(numero);
            __soapReq.addProperty(__info);
            __info = new PropertyInfo();
            __info.namespace = "http://etsmtl.ca/";
            __info.name = "PathFiche";
            __info.type = PropertyInfo.STRING_CLASS;
            __info.setValue(PathFiche);
            __soapReq.addProperty(__info);
            return __envelope;
        }

        @Override
        public Object ProcessResult(ExtendedSoapSerializationEnvelope __envelope, SoapObject __result) throws Exception {
            Object obj = __result.getProperty("GetFicheResult");
            if (obj != null && obj.getClass().equals(SoapPrimitive.class)) {
                SoapPrimitive j = (SoapPrimitive) __result.getProperty("GetFicheResult");
                return j.toString();
            }
            return null;
        }
    }, "http://etsmtl.ca/GetFiche");
}
Also used : SoapObject(org.ksoap2.serialization.SoapObject) SoapObject(org.ksoap2.serialization.SoapObject) PropertyInfo(org.ksoap2.serialization.PropertyInfo) SoapPrimitive(org.ksoap2.serialization.SoapPrimitive)

Aggregations

SoapObject (org.ksoap2.serialization.SoapObject)29 PropertyInfo (org.ksoap2.serialization.PropertyInfo)23 SoapPrimitive (org.ksoap2.serialization.SoapPrimitive)5 IOException (java.io.IOException)3 Handler (android.os.Handler)2 Message (android.os.Message)2 ArrayOfFicheEmploye (ca.etsmtl.applets.etsmobile.model.ArrayOfFicheEmploye)2 ListeDeCours (ca.etsmtl.applets.etsmobile.model.ListeDeCours)2 Entry (java.util.Map.Entry)2 SoapSerializationEnvelope (org.ksoap2.serialization.SoapSerializationEnvelope)2 HttpResponseException (org.ksoap2.transport.HttpResponseException)2 HttpTransportSE (org.ksoap2.transport.HttpTransportSE)2 Element (org.kxml2.kdom.Element)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 ArrayOfFicheEmployeDate (ca.etsmtl.applets.etsmobile.model.ArrayOfFicheEmployeDate)1 ArrayOfService (ca.etsmtl.applets.etsmobile.model.ArrayOfService)1 Etudiant (ca.etsmtl.applets.etsmobile.model.Etudiant)1 FicheEmploye (ca.etsmtl.applets.etsmobile.model.FicheEmploye)1 ListeDeSessions (ca.etsmtl.applets.etsmobile.model.ListeDeSessions)1 ListeDesElementsEvaluation (ca.etsmtl.applets.etsmobile.model.ListeDesElementsEvaluation)1