I call a .Net web service from my Blackberry app. After having nothing but trouble with KSoap2 I decided to do everything manually. Here is a snippet of code:
byte [] postDataBytes = soapRequestEnvelope.getBytes();
byte [] dataRetrieved;
try
{
HttpConnection connection = (HttpConnection)Connector.open(URL);
connection.setRequestMethod(HttpConnection.POST);
connection.setRequestProperty("soapaction", soapAction);
connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
os = connection.openOutputStream();
os.write(postDataBytes);
int rc = connection.getResponseCode();
if(rc == HttpConnection.HTTP_OK)
{
inputStream = connection.openInputStream();
dataRetrieved = new byte[(int)connection.getLength()];
int bytesRead = inputStream .read(dataRetrieved);
}
else
{
dataRetrieved = null;
}
String dataString = new String(dataRetrieved);
//HttpConnection = javax.microedition.io.HttpConnection
//inputStream = java.io.InputStream
The problem I'm having is that the XML I get back from the web service call gets cut short.
When I print the number of received bytes to the screen it says 1170 sometimes (which is actually the response size I'm expecting in this particular situation.)
But other times the received bytes is 702...... why 702???
I've tested about a dozen times in a row and got the following result:
1170, 702, 1170, 1170, 702, 1170, 1170, 702, 1170, 702, 1170, 702, 702, 702, 1170, 702
But why 702?? When it messes up and doesn't work why is it so consistent?? It's always allocating 1170 bytes though, but why does it sometimes only read 702??
This is very strange.
EDIT: I tried printing inputStream.available() to the screen as well for comparison, totally inconsistent. It varies between 0, 702 and 1170. Sometimes the available bytes is 0 or 702 and the bytes read is 1170. I'm totally confused.
Any help would be greatly appreciated.
Thank you