3
使用KSOAP爲accesing從Android的一個WSDL者地位解析SOAP響應現在用的是以下沒有安卓
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(BASIC_URL);
try {
StringEntity se = new StringEntity(SoapRequest, HTTP.UTF_8);
se.setChunked(true);
se.setContentType("text/xml");
httpPost.addHeader("Accept-Encoding", "gzip,deflate");
httpPost.addHeader("SOAPAction", SoapAction);
httpPost.addHeader("Content-Type", "text/xml;charset=UTF-8");
httpPost.addHeader(header);
httpPost.setEntity(se);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity resEntity = httpResponse.getEntity();
// response = EntityUtils.toString(resEntity);
return httpResponse;
} catch (Exception e) {
}
其中SoapRequest是肥皂串,得到了來自服務器的響應,但如何解析,因爲上午SOAP響應不使用HttpTransportSE和ksoap我沒有肥皂對象作爲響應。
- 這是從android訪問wsdl servise的正確方法嗎?
- 我可以皁對象轉換爲XML或JSON,然後解析它
樣本響應是
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org /soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetResponse xmlns="http://tempuri.org/">
<GetResult>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="First">
<xs:complexType>
<xs:sequence>
<xs:element name="FirstElement" type="xs:int" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<NewDataSet xmlns="">
<Exception diffgr:id="Exception1" msdata:rowOrder="0">
<ex_id>12</ex_id>
</Exception>
<Second diffgr:id="Second" msdata:rowOrder="0">
<SecondElement>66</SecondElement>
</Second>
</NewDataSet>
</GetResult>
</GetResponse>