Back to project page FrameLite.
The source code is released under:
GNU General Public License
If you think the Android project FrameLite listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.miku.framelite.api.webservice; //ww w .ja va 2 s . c o m import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.kxml2.kdom.Element; import com.miku.framelite.api.BaseRequest; import com.miku.framelite.api.RetResult; public abstract class AbstractWebServiceRequest<T,V> extends BaseRequest<T, V> { private static final int DEFAULT_CONNECT_TIMEOUT = 8 * 1000; private static final int DEFAULT_READ_TIMEOUT = 60 * 1000; protected abstract String getNameSpace(); protected abstract String getUrl(); protected abstract String getMethodName(); protected abstract String getSoapAction(); /** * ??????rawHttpEntity???????????V,???onParse????? * * @param rawResponse * @return ????????V * @throws Exception */ protected abstract V handlerRawResponse(Object rawResponse) throws Exception; protected Element[] getSoapHeader() { return null; } protected void addParams(SoapObject request) { } /** * ??????,???8?(???????) * * @return ??????????? */ protected int getConnectTimeOut() { return DEFAULT_CONNECT_TIMEOUT; } /** * ????????????1?? * @return */ protected int getReadTimeOut(){ return DEFAULT_READ_TIMEOUT; } @Override public V doInBackground(RetResult<T> result) { isCancelled=false; try { SoapSerializationEnvelope envelope = createEnvelope(); SoapObject request = new SoapObject(getNameSpace(), getMethodName()); addParams(request); envelope.setOutputSoapObject(request); WebServiceHttpTransportSE androidHttpTransport = new WebServiceHttpTransportSE(getUrl(),getConnectTimeOut(),getReadTimeOut()); androidHttpTransport.call(getSoapAction(), envelope); return handlerRawResponse(envelope.getResponse()); } catch (Exception e) { e.printStackTrace(); result.setMsg("??????????????"); } return null; } private SoapSerializationEnvelope createEnvelope() { SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); Element[] header = getSoapHeader(); if (header != null) { envelope.headerOut = header; } envelope.dotNet = true; return envelope; }; }