Android客户端WebService访问接口(Ksoap2Android调用.net服务端)

 
 
package com.nassoft.infomed.util;

import java.util.List;

import org.apache.http.message.BasicNameValuePair;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import com.nassoft.infomed.common.Constant;

/**
 * 
 * @ClassName: WSHelper 
 * @Description: TODO(WebService工具类) 
 * @author zyl 
 * @date 2012-12-17 下午3:28:24
 */
public class WSHelper {
    private final static String WSUrl=Constant.URL;// 设置URL
 
    private final static String namespace = Constant.NAMESPACE;// 设置命名空间
    /*************************************
     * 获取web services内容
     * @param url
     * @param params
     * @return
     *************************************/
    public static String GetResponse(String method,List<BasicNameValuePair> params){
         
        try {
            String url = WSUrl;
            SoapObject request = new SoapObject(namespace, method);
            for(int i=0,len=params.size();i<len;i++){
                request.addProperty(params.get(i).getName(), params.get(i).getValue());
            }
            SoapSerializationEnvelope envelope = 
                new SoapSerializationEnvelope(SoapEnvelope.VER11); 
            envelope.dotNet = true; 
            envelope.setOutputSoapObject(request); 
             
            // 3.0RC版本之后就没有AndroidHttpTransport这个类了
//            AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(url);
//            androidHttpTransport.call(namespace + method, envelope); 
            HttpTransportSE httpTransportSE = new HttpTransportSE(url);
            httpTransportSE.call(namespace + method, envelope);
             
            SoapPrimitive result = (SoapPrimitive)envelope.getResponse(); 
            return result.toString();
        } catch (Exception e) {
        	e.printStackTrace();
            return "Error:calling the web services error";
        }
    }

}
 
 

我不想要ksoap2android帮我解析xml

Turn debugging on for your httpTransport like so

httpTransport.debug = true;

and then set a breakpoint at

httpTransport.call(soapaction, envelope);

inspect the values of

httpTransport.requestDump
httpTransport.responseDump

参考:https://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks#How_to_see_raw_xml_request_and_response_e.g._for_debugging?

参考:http://www.cnblogs.com/jewleo/archive/2011/04/20/20110420_1.html

你可能感兴趣的:(Android客户端WebService访问接口(Ksoap2Android调用.net服务端))