android通过ksoap2对webservice的解析

首先需要下载ksoap2插件,ksoap2-android-assembly-2.4-jar-with-dependencies.jar,然后导入android的工程中

private static final String METHODNAME_DIARY = "queryAllDiaryByNoteBookId";
// WSDL文档的URL 注意这里要用ip,即使是本机也不能用localhost或者127.0.0.1代替
public static final String URL = "http://192.168.85.1:8080//axis2/services/";
public static final String NAMESPACE = "http://webservice.itRen";
private static final String URLClass = "NoteBookList";
SoapObject request = new SoapObject(Constant.NAMESPACE,	METHODNAME_DIARY);
		request.addProperty("notebookid",notebookID);
		String jsonString = webserviceOp(request);

	public static String webserviceOp(SoapObject request) {
		// 生成调用WebService方法的SOAP请求信息。该信息由SoapSerializationEnvelope对象描述
		// 构造方法设置SOAP协议的版本号:该版本号需要根据服务端WebService的版本号设置
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = false;
		
		// SoapSerializationEnvelope对象后,不要忘了设置SoapSerializationEnvelope类的bodyOut属性,该属性的值就是在第1步创建的SoapObject对象。
		envelope.setOutputSoapObject(request);
		// 创建HttpTransportSE对象。通过HttpTransportSE类的构造方法可以指定WebService的WSDL文档的URL
		AndroidHttpTransport transport = new AndroidHttpTransport(
				Constant.URL + URLClass);
		// 使用call方法调用WebService方法
		try {
			transport.call(null,
					envelope);
		} catch (IOException e) {
			// TODO Auto-generated
			// catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated
			// catch block
			e.printStackTrace();
		}
		// 使用getResponse方法获得WebService方法的返回结果
		SoapObject result = (SoapObject) envelope.bodyIn;
		String show=(String)result.getProperty(0).toString();
		return show;
	}




你可能感兴趣的:(android,webservice,String,url,文档,SOAP)