2013-04-17 2 views
1

Я разрабатываю приложение, которое использует веб-службу SOAP.SOAP-ответ не в формате XML

Когда я получаю ответ в текстовом виде или в лог-кошки это в следующем формате, как:

anyType{Results=anyType{Row=anyType{NAME=Demo; [email protected]; PHONENO=98607xxxxx; }; }; } 

Но в браузере ответ, как:

<env:Envelope 
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:ns0="http://testing.oi.com/"> 
    <env:Body> 
     <ns0:getDetailsResponse> 
      <ns0:return> 
       <Results> 
        <Row> 
         <NAME>Demo</NAME> 
         <EMAIL>[email protected]</EMAIL> 
         <PHONENO>98607xxxxx</PHONENO> 
        </Row> 
       </Results> 
      </ns0:return> 
     </ns0:getDetailsResponse> 
    </env:Body> 
</env:Envelope> 

Мой код вызова SOAP веб-службы выглядит следующим образом:

String NAMESPACE = "http://testing.oi.com/"; 
String URL = "http://192.168.1.xxx:8888/Testing-DemoTest-context-root/TestDemoSoapHttpPort"; 
String SOAP_ACTION = "http://testing.xx.com/getDetails"; 
String METHOD_NAME = "getDetails"; 

//Initialize soap request + add parameters 
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

//Declare the version of the SOAP request 
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
envelope.dotNet = true; 
envelope.setOutputSoapObject(request); 
envelope.implicitTypes = false; 

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

try {    
    androidHttpTransport.debug = true; 
//this is the actual part that will call the 
androidHttpTransport.call(SOAP_ACTION, envelope); 
// Get the SoapResult from the envelope body. 
SoapObject result = (SoapObject)envelope.bodyIn; 
//Xml.parse(result.toString(), dataHandler); 
hotelDetails = result.getProperty(0).toString(); 
Log.d("Rsp",Details); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

tv.setText(hotelDetails); 

Мои Java-код веб-службы выглядит следующим образом:

public class Test { 
    public Test() { 
    } 
    // Global Variable 
    Connection con; 
    CallableStatement cst; 
    String response; 
    ResultSet rs; 
    Statement stmt; 

    //DataBase Connection 
    public static Connection getConnection(){ 
     Connection con; 
     con = null; 

     try { 
      Class.forName("oracle.jdbc.driver.OracleDriver"); 
     } catch (ClassNotFoundException e) { 
      System.out.println("Server Connection Failed"); 
     } 

     String url="jdbc:oracle:thin:@abc.def.com:PortNo:SID"; 
     try { 
      con=DriverManager.getConnection(url,"UserName","Password"); 
      if(con!=null){ 
       System.out.println("Connection Success"+"\n"); 
      } 
     } catch (SQLException e) { 

     System.out.println("Connection Failed"); 
    } 
    return(con); 
} 

//XML Document Creation. 
public static Document createXMLDocument(ResultSet resultset, Document doc){ 
    ResultSetMetaData rsmd;  
    DocumentBuilderFactory factory; 
    DocumentBuilder builder; 
    doc = null; 
    Element results; 
    int colCount; 
    Connection con = getConnection();   

    try{ 
     factory = DocumentBuilderFactory.newInstance(); 
     builder= factory.newDocumentBuilder(); 
     doc= builder.newDocument(); 
     results = doc.createElement("Results"); 
     doc.appendChild(results); 
     rsmd = resultset.getMetaData(); 
     colCount = rsmd.getColumnCount(); 

     while (resultset.next()){ 
      Element row = doc.createElement("Row"); 
      results.appendChild(row); 

      for (int i = 1; i <= colCount; i++){ 
       String columnName = rsmd.getColumnName(i); 
       Object value = resultset.getObject(i); 
       if(value==null){ 
        value=" "; 
       } 

       Element node = doc.createElement(columnName); 
       if(columnName.equalsIgnoreCase("BEGIN_DATE")){ 
        String date= resultset.getString(i); 
        node.appendChild(doc.createTextNode(date)); 
        row.appendChild(node); 
       }else{ 
        node.appendChild(doc.createTextNode(value.toString())); 
        row.appendChild(node); 
       } 
      } 
     } 
    }catch (Exception e) { 
     e.printStackTrace(); 
    } 
    try { 
     con.close(); 
    } catch (SQLException e) { 
     e.printStackTrace(); 
    } 
    return(doc); 
} 

// Call Details 
@WebMethod 
public Document getDetails(){ 
    Document doc; 
    doc = null; 
    con=getConnection(); 
    try { 
     cst= con.prepareCall("{call callDetails (?)}"); 
     cst.registerOutParameter(1,OracleTypes.CURSOR); 
     cst.execute(); 
     rs = (ResultSet)cst.getObject(1); 
     doc = createXMLDocument(rs,doc); 
    }catch (SQLException e) { 
     System.out.println("No Such Record"); 
    } 

    try { 
     con.close(); 
    } catch (SQLException e) { 
     e.printStackTrace(); 
    } 
    return(doc); 
} 

Мне нужен ответ, как будто он находится в браузере в строке, поэтому я могу использовать синтаксический анализ и анализ синтаксиса. Я не понимаю, в чем проблема, почему я получаю такой ответ.

Прошу вас проинструктировать меня в этом выпуске или предложить мне, что мне теперь делать. Я в середине приложения и не могу двигаться дальше.

ответ

2

Я решил проблему получения ответа. Что я сделал это:

Я просто добавить:

androidHttpTransport.debug = true; 

перед:

androidHttpTransport.call(SOAP_ACTION, envelope); 

и после вызова я добавил:

String xml = androidHttpTransport.responseDump; 

И это я получаю ответ браузера в строке.

Смежные вопросы