我使用Ksoap2
将以下代码用于webservicepackage com.google.android.myWebService;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpsTransportSE;
//import org.ksoap2.transport.HttpTransport;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class myWebService extends Activity {
/** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://www.webservicex.net/GetWeatherByPlaceName";
private static final String METHOD_NAME = "GetWeatherByPlaceName";
private static final String NAMESPACE = "http://www.webservicex.net";
private static final String URL = "http://www.webservicex.net/WeatherForecast.asmx?WSDL";
private Object resultsRequestSOAP = null;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
TextView tv = new TextView(this);
setContentView(tv);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// SoapObject
request.addProperty("PlaceName", "new york");
//request.addProperty("lastname", "Williams");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
Log.d(null,"Status : set HttpTransport");
HttpsTransportSE androidHttpTransport = new HttpsTransportSE(URL, 443, "", 5000);
try {
Log.d(null,"Status : b4 Call");
androidHttpTransport.call(SOAP_ACTION, envelope);
Log.d(null,"Status : Call done");
resultsRequestSOAP = envelope.getResponse();
Log.d(null,"Status : Response received");
String[] results = (String[]) resultsRequestSOAP;
tv.setText(results[0]);
} catch (Exception aE) {
//aE.printStackTrace();
Log.d(null,"Exception: " + aE);
}
}
}
但它在logcat中提供以下输出:
03-29 16:57:50.961: DEBUG/installd(1096): DexInv: --- BEGIN '/data/app/vmdl42687.tmp' ---
03-29 16:57:51.601: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/xmlpull/v1/XmlPullParser;' has an earlier definition; blocking out
03-29 16:57:51.601: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/io/KXmlParser;' has an earlier definition; blocking out
03-29 16:57:51.601: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/xmlpull/v1/XmlSerializer;' has an earlier definition; blocking out
03-29 16:57:51.611: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/io/KXmlSerializer;' has an earlier definition; blocking out
03-29 16:57:51.611: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/kdom/Node;' has an earlier definition; blocking out
03-29 16:57:51.611: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/kdom/Document;' has an earlier definition; blocking out
03-29 16:57:51.611: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/kdom/Element;' has an earlier definition; blocking out
03-29 16:57:51.611: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/wap/Wbxml;' has an earlier definition; blocking out
03-29 16:57:51.621: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/wap/WbxmlParser;' has an earlier definition; blocking out
03-29 16:57:51.621: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/wap/WbxmlSerializer;' has an earlier definition; blocking out
03-29 16:57:51.621: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/wap/syncml/SyncML;' has an earlier definition; blocking out
03-29 16:57:51.621: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/wap/wml/Wml;' has an earlier definition; blocking out
03-29 16:57:51.621: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/wap/wv/WV;' has an earlier definition; blocking out
03-29 16:57:51.621: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/xmlpull/v1/XmlPullParserException;' has an earlier definition; blocking out
03-29 16:57:51.631: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/xmlpull/v1/XmlPullParserFactory;' has an earlier definition; blocking out
03-29 16:57:51.751: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.761: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.761: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.771: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.771: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.771: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.771: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.791: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/kxml2/io/KXmlSerializer;'
03-29 16:57:51.801: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/xmlpull/v1/XmlPullParser;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/io/KXmlParser;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/xmlpull/v1/XmlSerializer;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/io/KXmlSerializer;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/kdom/Node;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/kdom/Document;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/kdom/Element;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/wap/Wbxml;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/wap/WbxmlParser;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/wap/WbxmlSerializer;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/wap/syncml/SyncML;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/wap/wml/Wml;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/wap/wv/WV;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/xmlpull/v1/XmlPullParserException;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/xmlpull/v1/XmlPullParserFactory;': multiple definitions
03-29 16:57:51.821: DEBUG/dalvikvm(6892): DexOpt: load 60ms, verify 186ms, opt 8ms
03-29 16:57:51.881: DEBUG/installd(1096): DexInv: --- END '/data/app/vmdl42687.tmp' (success) ---
我的代码中有什么问题?
答案 0 :(得分:2)
答案 1 :(得分:0)
这是一个.Net webservice,你需要设置
envelope.dotNet = true;
在执行请求之前。
答案 2 :(得分:0)
这不是错误,只是警告kxml2和xmlpull类验证。
您是导入的ksoap2.jar库,供您的项目进行构建。但是ksoap2.jar库里面有一个kxml2和xmlpull jar。这些罐子已经包含在Android OS中。因此,DexOpt实用程序无法验证您的apk二进制文件中的库。别担心。操作系统只会使用自己的kxml2和xmlpull库而不是你的库。