如何在 android 中发布对 SOAP 服务的请求?
请给我一些例子
谢谢你给我分享知识
使用KSoap 库,这是我项目中的代码片段:
SoapObject soapObject = new SoapObject(NAMESPACE_NIST_IMPORT,
METHOD_NAME_NIST_IMPORT);
ImportNistFileReq nistReq = new ImportNistFileReq(nistFile);
PropertyInfo pi = new PropertyInfo();
pi.setName("req");
pi.setValue(nistReq);
pi.setType(nistReq.getClass());
soapObject.addProperty(pi);
SoapSerializationEnvelope soapSerializationEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
new MarshalBase64().register(soapSerializationEnvelope);
soapSerializationEnvelope.setOutputSoapObject(soapObject);
soapSerializationEnvelope.addMapping(NAMESPACE_NIST_IMPORT, "ImportNistFileReq", new ImportNistFileReq().getClass());
soapSerializationEnvelope.dotNet = true;
Object objectResult = null;
try {
HttpTransportSE httpTransportSE = new HttpTransportSE(
URL_NIST_IMPORT);
httpTransportSE.debug = true;
httpTransportSE.call(SOAP_ACTION_NIST_IMPORT, soapSerializationEnvelope);
String host = httpTransportSE.getPath();
Log.i("HOST: ", host);
objectResult = (Object) soapSerializationEnvelope.getResponse();
} catch (IOException e) {
Log.e("IO: ", e.getMessage());
} catch (XmlPullParserException e) {
Log.e("XML: ", e.getMessage());
}
这段代码发送一个NIST 文件,表示为 Web 服务的byte array
编码Byte64
。像这样的请求应该在一个单独的线程中调用,比如AsyncTask ..
常数: