我正在为ideone.com网络服务开发Android客户端。此Web服务使您能够在在线Web服务器上执行各种语言的代码,并获取您执行的代码的输出。此Web服务的WSDL的地址是:
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", "13@silvi");
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;
}
作为响应,输出参数的值为null。如果出现任何错误,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">13@silvi</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>
我从网络服务收到的回复是:
<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">13@silvi</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=}
这是我从网络服务中收到的回复。但不是这样,我应该收到:
itemType{key="output" value=<Output_text>}
请帮我确定问题。
答案 0 :(得分:0)
从webservice返回的值为null。