我是SOAP的新開發者,所以引導我如何在android中調用soap api。 這裏是我發現的方法,但不知道它是如何工作的。我已經下載this庫Android和SOAP api的連接
public static String connectSOAP(String url, String soapNamespace, String soapAction, String soapMethod, Hashtable<String, String> HT) {
String result = null;
SoapObject request = new SoapObject(soapNamespace, soapMethod);
if (HT != null) {
Enumeration<String> en = HT.keys();
while (en.hasMoreElements()) {
Object k = en.nextElement();
Object v = HT.get(k);
request.addProperty(k.toString(), v);
System.out.println("key = " + k.toString() + "; value = " + v);
}
}
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
//envelope.bodyOut = request;
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
//envelope.getResponse();
try {
androidHttpTransport.call(soapAction, envelope);
if (envelope.bodyIn instanceof SoapFault) {
result = ((SoapFault) envelope.bodyIn).faultstring;
} else {
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
result = resultsRequestSOAP.getProperty(0).toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
這是方法,我想作爲一個API調用來使用,但不知道怎麼用這個。 所以請幫助我。
[這裏](https://code.tutsplus.com/tutorials/consuming-web-services-with-ksoap--mobile-21242)你將會逐步獲得指令。 – sodhankit
好的,謝謝@sodhankit。如果我有任何問題,我會回到這一點。 –