Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7639817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:31:09+00:00 2026-05-31T08:31:09+00:00

I call a .Net web service from my Blackberry app. After having nothing but

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:31:11+00:00Added an answer on May 31, 2026 at 8:31 am

    After my sort of vague comment, I suppose I should specify what I meant by “put that read in a loop”. As defined, read will return the number of bytes read, or -1 if the end of file is reached.

    When reading from a socket, you may be calling read() before all of the data has been returned to you from the server. The practical effect of this is that you call read() and you get back less data than you’re expecting. This simply means you need to call it again (and again, and again) until you get all the data.

    I would suggest using a simple fixed size buffer and looping through read() until you get -1 and doing something with each chunk (writing it to a file, for example.) This prevents you from needing to have the entire file in memory. For example:

    byte buf[1024];
    int len;
    
    while((len = read(buf)) >= 0)
    {
        /* do something with len bytes of buf */
    }
    

    Of course, you may have a guarantee that the file will be small and you really do want the whole thing in memory. In that case, you can (as you did above) just allocate a buffer of connection.getLength() size, however you’ll need to call the 3-arg read(byte[], int, int) and do a little more housekeeping:

    int remain = (int) connection.getLength();
    byte buf[remain];
    int offset = 0, len;
    
    while((len = read(buf, offset, remain)) >= 0)
    {
        offset += len;
        remain -= len;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I call a .net web service from an Objective C iPhone app?
I'm trying to call a Java Web Service from an MVC3 .NET web app
I am trying to call a web service from asp.net 3.5 application. I have
I tried to call a .NET web service with KSOAP2 and it throws an
Calling a .net SOAP1.1 web service from android using ksoap2 lib I met a
I need to call Java web service from .Net application and that web service
I have an asp.net MVC2 application that needs to call a web service from
I am trying to return an html table from a asp.net web service but
How can I call a .Net Web Service from within php. Are there any
I am trying to call a web service from a BizTalk (2006) orchestration. Having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.