android 使用kSOAP2出现“double ID exception”

最近在做一个和webservice使用soap进行交互的应用,获取webservice返回的数据时遇到一个错误java.lang.RuntimeException: double IDouble ID exception”,百度上找不到答案,后来Google了一下,在stackOverflow上找到了解决办法,原来是webservice返回的xml数据多了一个节点<diffgr:before>,在后台处理了一下后运行正常,现把解决办法说一下。

我的代码:

try {
			// 1、指定 WebService 的命名空间和调用方法 ;
			SoapObject rpc = new SoapObject(ConstantData.NAMESPACE,
					ConstantData.GETNOTICE_METHOD_NAME);
			System.out.println("1*******************");
			// 2、设置调用方法的参数值,如果没有参数,可以省略
			// 3、生成调用Webservice方法的SOAP请求信息。
			// 创建SoapSerializationEnvelope对象时需要通过SoapSerializationEnvelope类的构造方法设置SOAP协议的版本号。
			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
					SoapEnvelope.VER11);
			envelope.bodyOut = rpc;
			System.out.println("2*******************");
			// 这里如果设置为TRUE,那么在服务器端将获取不到参数值(如:将这些数据插入到数据库中的话)
			envelope.dotNet = true;
			System.out.println("3*******************");
			// 在创建SoapSerializationEnvelope对象后,不要忘了设置SOAPSoapSerializationEnvelope类的bodyOut属性
			envelope.setOutputSoapObject(rpc);
			// 4、创建HttpTransportsSE对象
			NewHttpTransportSE ht = new NewHttpTransportSE(ConstantData.STU_URL);
			ht.debug = true;
			System.out.println("4*******************");
			// 5、使用call方法调用WebService方法
			System.out.println("使用call方法调用WebService方法");
			ht.call(ConstantData.GETNOTICE_SOAP_ACTION, envelope, null);
			System.out.println("5*******************");
			// 6、获得WebService方法的返回结果
			SoapObject response = (SoapObject) envelope.getResponse();
			SoapObject detail = (SoapObject) response.getProperty(1);
			SoapObject newdataset = (SoapObject) detail
					.getProperty("NewDataSet");
			SoapObject allNotice = (SoapObject) newdataset
					.getProperty("AllNotice");
			System.out.println("response节点个数" + response.getPropertyCount());
			System.out
					.println("newdataset节点个数" + newdataset.getPropertyCount());
			System.out.println("allNotice节点个数" + allNotice.getPropertyCount());
			for (int i = 0; i < newdataset.getPropertyCount(); i++) {
				SoapObject soapChilds = (SoapObject) newdataset.getProperty(i);
				String postID = soapChilds.getProperty("postID").toString();
				String postTitle = soapChilds.getProperty("postTitle")
						.toString();
				String postContent=soapChilds.getProperty("postContent").toString();
				String postDate = soapChilds.getProperty("postDate").toString();
				String postPersonName = soapChilds
						.getProperty("postPersonName").toString();
				String postContentText = soapChilds.getProperty(
						"postContentText").toString();
				noticeMap = new HashMap<String, String>(); // 存放到MAP里面
				noticeMap.put("postID", postID);
				noticeMap.put("postTitle", postTitle);
				noticeMap.put("postContent", postContent);
				noticeMap.put("postDate", postDate);
				noticeMap.put("postPersonName", postPersonName);
				noticeMap.put("postContentText", postContentText);
				System.out.println(postID);
				System.out.println(postTitle);
				System.out.println(postDate);
				System.out.println(postPersonName);
				System.out.println(postContentText);
				noticelist.add(noticeMap);
			}
			// System.out.println(allNotice);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}

Exception

java.lang.RuntimeException: double ID
at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:407)
at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
 at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
 at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
 at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
 at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:151)
 at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
 at org.ksoap2.transport.Transport.parseResponse(Transport.java:116)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:235)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:114)
at com.menthatech.soap_login_test.SampleSoapTest_LoginActivity.onClick(SampleSoapTest_LoginActivity.java:94)
at android.view.View.performClick(View.java:2408)
at android.view.View$PerformClick.run(View.java:8816)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

解决办法:

remove the <diffgr:before> tag and its inner contents.

http://stackoverflow.com/questions/6073129/how-to-remove-diffgrbefore-content-from-returned-dataset-via-webservice

你可能感兴趣的:(android 使用kSOAP2出现“double ID exception”)