在android中解析soap响应而不使用kso​​ap

时间:2015-05-26 10:28:23

标签: android soap wsdl

使用以下

从android am访问wsdl servise
    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 我不有一个肥皂对象作为回应。

  1. 这是从android访问wsdl servise的正确方法吗?
  2. 我可以将soap对象转换为xml或json,然后解析它
  3. 样本回复是

     <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>
    

1 个答案:

答案 0 :(得分:0)

我们可以解析Soap响应作为解析xml.Using xmlpull解析器我们可以提取xml标签。认为他们不需要 HttpTransportSE ksoap

ant -Dj2ee.server.home=D:\apache-tomcat-8.0.23 clean

ant -Dj2ee.server.home=D:\apache-tomcat-8.0.23 compile

ant -Dj2ee.server.home=D:\apache-tomcat-8.0.23 dist
相关问题