我是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。如果我有任何问题,我会回到这一点。 –