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>