XML格式的SOAP响应不 [英] SOAP response not in XML format

查看:188
本文介绍了XML格式的SOAP响应不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发消费SOAP Web服务的应用程序。

I am developing an application which consume SOAP web service.

当我得到在文本视图中或登录猫它是下列格式的响应:

When i am getting the response in text view or in log-cat it is in following format as :

anyType{Results=anyType{Row=anyType{NAME=Demo; EMAIL=m.m@gmail.com; PHONENO=98607xxxxx; }; }; }

但在浏览器的响应是这样的:

But on browser the response is like :

<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>m.m@gmail.com</EMAIL>
                        <PHONENO>98607xxxxx</PHONENO>
                    </Row>
                </Results>
            </ns0:return>
        </ns0:getDetailsResponse>
    </env:Body>
</env:Envelope>

调用SOAP Web服务的我的code是如下:

My code of calling SOAP web service is as follows :

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 Web服务code是如下:

My Java web service code is as follows :

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);
}

我想回应像它在字符串浏览器,以便我可以使用SAX解析和分析数据。我没有得到什么是为什么我收到这样的反应的问题。

I want the response as like it is on browser in string so that i can use sax parsing and parse data. I am not getting what is the issue that why i am getting such response.

请指导我在这个问题上还是建议我,我应该怎么做。我在应用程序的中间,并且可以不能够更远移动

Please guide me in this issue or suggest me what should i do now. I am in the middle of app and can not able to move farther.

推荐答案

我解决了越来越响应的问题。
我做的是:

I solved the issue of getting response. What i done is :

我只需要添加:

androidHttpTransport.debug = true;

androidHttpTransport.call(SOAP_ACTION, envelope);

和呼叫我加入后:

String xml = androidHttpTransport.responseDump;

和本我得到一个字符串中的浏览器的响应。

And by this i am getting the browser response in a string.

这篇关于XML格式的SOAP响应不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆