Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

New Member
Posts: 1
Registered: ‎03-22-2011
My Device: simulator
My Carrier: any

Consuming web services in Blackberry

Hi, I am using Blackberry plugin for Java-Eclipse to write blackberry code on Windows XP SP3

I am using ksoap2.jar in my application for webservice call.


My webservice having one method called "HelloServer".


This code will return "java.io.InterruptedIOException: Local connection timed out after ~ 120000" exception.


Following is the code


1.How can i solve this problem..


2. What are the ways i have to implement in my code.





My .NET Web Service Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace HelloWorldService
    //[WebService(Namespace = "http://tempuri.org/")]
    [WebService(Namespace = "http://localhost:2901/")]
    //[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Service : System.Web.Services.WebService


        public String HelloServer(String msg)
            return "From Server, Hello - " + msg;

        public String fnAddNumbers(int a, int b)
            return "From Server, Hello - " + (a + b);

        public String ShowMessage()
            return "Welcome to KSoap2 Library";

My BlackBerry Code

package com.criagagreen.sample;

import java.util.Date;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

//import net.rim.device.api.system.*;

public class HelloWorld extends UiApplication {
    public static void main(String[] args) {
        HelloWorld theApp = new HelloWorld();

    public HelloWorld() {
        pushScreen(new HelloWorldScreen());
        //String serviceUrl = "http:// <SERVER>/HelloWorldService/Service.asmx";
        String serviceUrl = "http://localhost:2901/Service.asmx";
        String serviceNamespace = "http://tempuri.org/";
        String soapAction = "http://localhost:2901/HelloServer";

        SoapObject rpc = new SoapObject(serviceNamespace, "HelloServer");

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(

        envelope.bodyOut = rpc;
        envelope.dotNet = true;
        envelope.encodingStyle = SoapSerializationEnvelope.XSD;
        rpc.addProperty("msg", (new Date()).toString());

        HttpTransport ht = new HttpTransport(serviceUrl);
        ht.debug = true;
        String result;

        try {
            ht.call(soapAction, envelope);
            result = (envelope.getResponse()).toString();
        } catch (Exception ex) {
            result = ex.toString();
        ((HelloWorldScreen) this.getActiveScreen()).setScreenTest(result);

final class HelloWorldScreen extends MainScreen

    private RichTextField textField;

    public HelloWorldScreen() {
        LabelField title = new LabelField("HelloWorld Web Service Sample",
                LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
        textField = new RichTextField("Hello World! from Web Service");

    public void setScreenTest(String text) {

    public boolean onClose() {
        Dialog.alert("Goodbye! from Web Service");
        return true;


Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Consuming web services in Blackberry

I'm not a Web Services expert, so this is just a guess.


Start the MDS Service, this should establish connectivity for the URL you are using.


You will, when you take this to the device, need to understand connectivity better.  I recommend that you review the KB article at least:



There are a number of other Threads and KB articles and videos that talk about Network Connectivity.  This is more complicated on the BlackBerry than it probably needs to be, and I think you are going to have to master it to make your application work properly, so please look round for more information.


Good luck.




Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Consuming web services in Blackberry

To add something to Peter's reply: I don't think MDS (once you start it) is going to allow you to connect to "localhost".


I usually set up a name in the hosts file and pioint it to the local address.


Posts: 105
Registered: ‎06-23-2010
My Device: 9000
My Carrier: vodaphone

Re: Consuming web services in Blackberry


Also, and I am sure you probably know this coming from Android, I highly recommend that you only use asynchronous calls to the web service. I used ksoap for a while but finally gave up. In the meantime I am using WSClient++ (3rd party, no association with them beyond a customer) which generates the proxy classes and completely eliminates the need for ksoap.



Press Kudos if this helped - ;-)