我想学习如何在 Android 中使用 webSservices。目前,我有一个带有 wsdl 文件的服务器,我可以从中调用所需的 Web 服务。
我的问题是我得到了服务器的响应,我想提取一些对我来说很有趣的信息,例如用户 ID 或类似的东西。
这是我的代码:
public class TestBookSoapActivity extends Activity {
private static final String SOAP_ACTION = "JournalArticles";
private static final String METHOD_NAME = "JournalArticles";
private static final String NAMESPACE = "http://api.mdpi.com/ws/";
private static final String URL = "http://api.mdpi.com/ws/server.php";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
executeAppelSOAP();
}
private void executeAppelSOAP() {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("JournalID", 1);
request.addProperty("Volume", 12);
request.addProperty("Issue", 1);
SoapSerializationEnvelope enveloppe = new SoapSerializationEnvelope(SoapEnvelope.VER11);
enveloppe.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport (URL);
try {
androidHttpTransport.call(SOAP_ACTION, enveloppe);
Object resultat = enveloppe.getResponse();
System.out.println(" Journal Articles= " + resultat.toString());
} catch(Exception e) {
e.printStackTrace();
System.out.println("Problem");
}
}
我可以使用 enveloppe.parse() 方法吗?如果可以,如何使用?
谢谢你。