我有兩個關於Ksoap2的問題。Android - WSDL/Ksoap2
首先,下面是我的web服務請求的XML示例。
請求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://my-webservice.com/">
<soapenv:Header/>
<soapenv:Body>
<web:getBoard>
<!--Optional:-->
<language></language>
<identification login="" pwd=""/>
</web:getBoard>
</soapenv:Body>
</soapenv:Envelope>
迴應:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:getBoardResponse xmlns:ns2="http://my-webservice.com/">
<board code="NONE">WhatIWant</board>
<board code="HALF">blabla</board>
<board code="FULL">blablah</board>
<board code="RONL">blablalblba</board>
<board code="BRKF">blabla</board>
<board code="ALLI">blablablah</board>
</ns2:getBoardResponse>
</soap:Body>
</soap:Envelope>
我必須設置爲DATAS領域: 「語言」, 「登錄」 和 「PWD」,但我不知道使用的好方法......(方法addProperty或setProperty爲現場的「語言」?)
public class CallRefservices {
private static final String NAMESPACE = "http://api.myapi.com/test/ws/test";
private static final String URL = "http://api.myapi.com/test/ws/test?wsdl";
private static final String SOAP_ACTION = "getBoard";
private static final String METHOD_NAME = "getBoard";
Boolean getConnection(String login, String pwd) {
Boolean checkBoardType = false;
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("login", login);
request.addProperty("pwd", pwd);
request.addProperty("language", "FR");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject objetSOAP = (SoapObject)envelope.getResponse();
checkBoardType = this.parserObjet(objetSOAP);
} catch (Exception e) {
Log.e("getConnection", "", e);
}
return checkBoardType;
}
private boolean parserObjet(SoapObject objet) {
SoapObject boardObjet = (SoapObject)objet.getProperty("board");
String board = boardObjet.getProperty("NONE").toString();
if (board == "WhatIWant")
return true;
else
return false;
}
}
我還需要有關分析器。 什麼樣的解析器用於Ksoap2? (DOM,SAX) 我使用的是好方法嗎?
任何幫助表示讚賞! 快樂聖誕btw;)。
編輯:
嗯,我的問題是,發送的XML如下:
[...] <login i:type="d:string">mylogin</login><pwd i:type="d:string">mypassword</pwd><language i:type="d:string">FR</language></n0:getBoardTypes></v:Body></v:Envelope>
而我需要:
[...] <language></language>
<identification login="" pwd=""/>
:|
編輯2:
嗨,托米斯拉夫,謝謝你的時間和你的答案! 我試過你的解決方案,但它無法正常工作。
我假設送東西,如:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://my.api.com/">
<soapenv:Header/>
<soapenv:Body>
<web:getBoard>
<language>FR</language>
<identification login="username" pwd="mypwd"/>
</web:getBoard>
</soapenv:Body>
</soapenv:Envelope>
有了您的解決方案,我是這樣的:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://my.api.com/">
<soapenv:Header/>
<soapenv:Body>
<web:getBoard>
<language>FR</language>
<identification>
<login>username</login>
<pwd>mypwd</pwd>
</identification>
</web:getBoard>
</soapenv:Body>
</soapenv:Envelope>
我想我會創建一個XML模板...:/ !
問題是什麼? addProperty正確添加所有屬性。這段代碼是否失敗?如果是這樣,什麼是例外? – 2011-12-23 14:54:50
那麼Web服務不能識別它? – 2011-12-26 14:10:10