我正在爲ideone.com web服務開發Android客戶端。該Web服務使您能夠在在線Web服務器上以各種語言執行代碼,並獲取您執行的代碼的輸出。在WSDL此Web服務的地址是:無法使用android中的KSOAP2從Webservice接收參數
http://ideone.com/api/1/service.wsdl
我使用KSOAP2.4通過Android應用程序與Web服務進行通信。但是我沒有從Web服務中正確地收到響應。我從Web服務收到的響應包含最後四個參數的空值。這裏是我用來調用Web服務的代碼:
public IdeoneSubmissionDetails getSubmissionDetails(String link,
Boolean withSource, Boolean withInput, Boolean withOutput,
Boolean withStderr, Boolean withCmpinfo) {
IdeoneSubmissionDetails ret = null;
Hashtable<String, Object> data = new Hashtable<String, Object>();
try {
SoapObject request = new SoapObject(NAMESPACE,"getSubmissionDetails");
request.addProperty("user", "ashwanikumar");
request.addProperty("pass", "[email protected]");
request.addProperty("link", link);
request.addProperty("withSource", withSource);
request.addProperty("withInput", withInput);
request.addProperty("withOutput", withOutput);
request.addProperty("withStderr", withStderr);
request.addProperty("withCmpinfo", withCmpinfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE transport = new HttpTransportSE(URL);
transport.debug = true;
transport.call(SOAP_ACTION + "getSubmissionDetails", envelope);
SoapObject so = (SoapObject) envelope.bodyIn;
SoapObject so2 = (SoapObject) so.getProperty(0);
int count = so2.getPropertyCount();
for (int i = 0; i < count; ++i) {
SoapObject so4 = (SoapObject) so2.getProperty(i);
String key = so4.getProperty(0).toString();
Log.i("Key", key);
Object val = so4.getProperty(1);
Log.i("Object",val.toString());
data.put(key, val);
}
String error = (String) data.get("error");
if (!error.equals("OK")) {
System.out.println("Error occurred: " + error);
return null;
}
ret = new IdeoneSubmissionDetails();
ret.langId = (Integer) data.get("result");
ret.langName = (String) data.get("langName");
ret.langVersion = (String) data.get("langVersion");
ret.date = (String) data.get("date");
ret.time = Float.valueOf(((SoapPrimitive) data.get("time"))
.toString());
ret.result = (Integer) data.get("result");
ret.status = (Integer) data.get("status");
ret.memory = (Integer) data.get("memory");
ret.signal = (Integer) data.get("signal");
ret.isPublic = (Boolean) data.get("public");
if (withSource.booleanValue()) {
ret.source = (String) data.get("source");
}
if (withInput.booleanValue()) {
ret.input = (String) data.get("input");
}
if (withOutput.booleanValue()) {
ret.output = (String) data.get("output");
}
if (withStderr.booleanValue()) {
ret.stderr = (String) data.get("stderr");
}
if (withCmpinfo.booleanValue()) {
ret.cmpinfo = (String) data.get("cmpinfo");
}
} catch (IOException ex) {
System.out.println("IO Error");
} catch (NumberFormatException ex) {
System.out.println("Number Format Error");
} catch (Exception ex) {
System.out.println("Error "+ex.toString());
}
return ret;
}
作爲響應,輸出參數的值爲空。如果出現任何錯誤,Stderr將返回錯誤信息。在成功執行代碼時,輸出參數應包含您執行的代碼的輸出。 檢查Web服務的執行是否使用SOAPUI。下面是我曾經提交關於web服務的代碼的請求:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://ideone.com/api/1/service">
<soapenv:Header/>
<soapenv:Body>
<ser:createSubmission soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<user xsi:type="xsd:string">ashwanikumar</user>
<pass xsi:type="xsd:string">[email protected]</pass>
<sourceCode xsi:type="xsd:string">class Main{public static void main (String[] args){ System.out.println("Hello");}}</sourceCode>
<language xsi:type="xsd:int">10</language>
<input xsi:type="xsd:string"></input>
<run xsi:type="xsd:boolean">true</run>
<private xsi:type="xsd:boolean">false</private>
</ser:createSubmission>
</soapenv:Body>
</soapenv:Envelope>
從web服務i接收的響應:
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ideone.com/api/1/service" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:createSubmissionResponse>
<return xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">error</key>
<value xsi:type="xsd:string">OK</value>
</item>
<item>
<key xsi:type="xsd:string">link</key>
<value xsi:type="xsd:string">8GaBJ</value>
</item>
</return>
</ns1:createSubmissionResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
前面的請求指定的代碼已提交成功,你可以使用鏈接
參數8GaBJ指定提交ID訪問我創建並用於稍後參考提交。 我創建的第二個請求用於執行提交詳細信息,這是在使用KSOAP2 Android客戶端調用時返回不正確響應的方法。下面是代碼:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://ideone.com/api/1/service">
<soapenv:Header/>
<soapenv:Body>
<ser:getSubmissionDetails soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<user xsi:type="xsd:string">ashwanikumar</user>
<pass xsi:type="xsd:string">[email protected]</pass>
<link xsi:type="xsd:string">8GaBJ</link>
<withSource xsi:type="xsd:boolean">TRUE</withSource>
<withInput xsi:type="xsd:boolean">TRUE</withInput>
<withOutput xsi:type="xsd:boolean">TRUE</withOutput>
<withStderr xsi:type="xsd:boolean">TRUE</withStderr>
<withCmpinfo xsi:type="xsd:boolean">TRUE</withCmpinfo>
</ser:getSubmissionDetails>
</soapenv:Body>
</soapenv:Envelope>
收到的反應是:
<SOAP-ENV:Body>
<ns1:getSubmissionDetailsResponse>
<return xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">error</key>
<value xsi:type="xsd:string">OK</value>
</item>
<item>
<key xsi:type="xsd:string">langId</key>
<value xsi:type="xsd:int">10</value>
</item>
<item>
<key xsi:type="xsd:string">langName</key>
<value xsi:type="xsd:string">Java</value>
</item>
<item>
<key xsi:type="xsd:string">langVersion</key>
<value xsi:type="xsd:string">sun-jdk-1.6.0.31</value>
</item>
<item>
<key xsi:type="xsd:string">time</key>
<value xsi:type="xsd:float">0.03</value>
</item>
<item>
<key xsi:type="xsd:string">date</key>
<value xsi:type="xsd:string">2012-03-29 07:30:29</value>
</item>
<item>
<key xsi:type="xsd:string">status</key>
<value xsi:type="xsd:int">0</value>
</item>
<item>
<key xsi:type="xsd:string">result</key>
<value xsi:type="xsd:int">15</value>
</item>
<item>
<key xsi:type="xsd:string">memory</key>
<value xsi:type="xsd:int">245632</value>
</item>
<item>
<key xsi:type="xsd:string">signal</key>
<value xsi:type="xsd:int">0</value>
</item>
<item>
<key xsi:type="xsd:string">public</key>
<value xsi:type="xsd:boolean">true</value>
</item>
<item>
<key xsi:type="xsd:string">source</key>
<value xsi:type="xsd:string">class Main{public static void main (String[] args){ System.out.println("Hello");}}</value>
</item>
<item>
<key xsi:type="xsd:string">input</key>
<value xsi:type="xsd:string"/>
</item>
<item>
<key xsi:type="xsd:string">output</key>
<value xsi:type="xsd:string">Hello</value>
</item>
<item>
<key xsi:type="xsd:string">stderr</key>
<value xsi:type="xsd:string"/>
</item>
<item>
<key xsi:type="xsd:string">cmpinfo</key>
<value xsi:type="xsd:string"/>
</item>
</return>
</ns1:getSubmissionDetailsResponse>
</SOAP-ENV:Body>
請注意,下列項目的值是正確的
<item>
<key xsi:type="xsd:string">input</key>
<value xsi:type="xsd:string"/>
</item>
<item>
<key xsi:type="xsd:string">output</key>
<value xsi:type="xsd:string">Hello</value>
</item>
<item>
<key xsi:type="xsd:string">stderr</key>
<value xsi:type="xsd:string"/>
</item>
<item>
<key xsi:type="xsd:string">cmpinfo</key>
<value xsi:type="xsd:string"/>
</item>
,但如果我看的響應我在Android中收到告訴我一個完全不同的故事。
itemType{key="output" value=}
這是我從Web服務收到的迴應。但代之以,我應該收到:
itemType{key="output" value=<Output_text>}
請幫我找出問題。
請幫助我無法找到解決這個問題的方法,我有幾個Web服務開發人員的話,但沒有人能夠解決問題... – 2012-04-10 11:02:13