开发者

Stream Error in Soap Connection

开发者 https://www.devze.com 2023-04-02 11:42 出处:网络
I develop android application in java. And, this application connects .net soap application. It is ok, it works (i use开发者_Go百科 http post method).

I develop android application in java. And, this application connects .net soap application. It is ok, it works (i use开发者_Go百科 http post method). My actual problem is web service returns big and huge (especially contains html --cdata source code) data. So, when i request (such as, getReports methods) to web service, it returns about 3 - 5 mb stream data, causes outofmemory. Because of this, i couldn't parse it. I know my connection method cannot be true. How can i implement truely if i make a mistake?

Thanks in advance.

String NAMESPACE = "http://tempuri.org/lorem";
String SURL = "http://www.test.com/lorem/test.asmx";
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
xml += "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://tempuri.org/\">"
        + "<soapenv:Header/><soapenv:Body>"
        + "<web:getReport><web:strLang>strLang</web:strLang></web:getReport>"
        + "</soapenv:Body></soapenv:Envelope>";
URLConnection connection = url.openConnection();
HttpURLConnection httpconn = (HttpURLConnection) connection;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
bout.write(xml.getBytes());
byte[] b = bout.toByteArray();
httpconn.setRequestProperty("SOAPAction", Namespace+ "/" + "getReport");
httpconn.setRequestProperty("Accept-Encoding","gzip,deflate");
httpconn.setRequestProperty("Host","www.test.com");
httpconn.setRequestMethod("POST");
httpconn.setDoInput(true);
httpconn.setDoOutput(true);
httpconn.connect();
OutputStream out = httpconn.getOutputStream();
out.write(b);
InputStreamReader isr = new InputStreamReader(httpconn.getInputStream());
BufferedReader in = new BufferedReader(isr);

String inputLine = "";
StringBuffer parsingData = new StringBuffer();
while (null != (inputLine = in.readLine())) {
    // OutOfMemory Error
    parsingData.append(inputLine);
}

/*
* parsingMethods (parsingData); 
*/


Ksoap does support headers here is how

Element AuthHeader = new Element();
AuthHeader.setName("Auth");
AuthHeader.setNamespace(namespace);

Element element = new Element();
element.setName("Username");
element.setNamespace(namespace);
element.addChild(Element.TEXT, username);
AuthHeader.addChild(Element.ELEMENT, element);

element = new Element();
element.setName("Password");
element.setNamespace(namespace);
element.addChild(Element.TEXT, password);
AuthHeader.addChild(Element.ELEMENT, element);

headers[0] = AuthHeader;

envelope.headerOut = headers;
0

精彩评论

暂无评论...
验证码 换一张
取 消