Question

I am working on a blackberry application. I need to call soap webservices, but I am unable to do so, and am getting null as a response. Following is my code:

private static final String CONNECTION_PARAMS = ";deviceside=true";

SoapObject request = new SoapObject("http://service.action.com/", 
                                    "findActiveSecurities");            

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = request;         
HttpTransportBasicAuth ht = 
     new HttpTransportBasicAuth("http://myurl.com/ebclient/services/MobileClientService?wsdl"+CONNECTION_PARAMS, 
                                "myusername", 
                                "mypassword");

PropertyInfo propInfo=new PropertyInfo();
propInfo.type=PropertyInfo.INTEGER_CLASS;

//adding parameters
request.addProperty("arg0","NSE");
request.addProperty("arg1","0");
request.addProperty("arg2","100");


envelope.setOutputSoapObject(request);

try {
    ht.call(SOAP_ACTION, envelope);
    result = (SoapObject)envelope.getResponse();
    System.out.println(result);
} catch (IOException e) {
    e.printStackTrace();
} catch (XmlPullParserException e) {
    e.printStackTrace();
}

I am getting null as a result.Please have a look at the code and help me to correct it. Thanks in advance

Was it helpful?

Solution

Actually the problem was instead of passing 0 and 100 as String ...

request.addProperty("arg0","NSE");
request.addProperty("arg1","0");
request.addProperty("arg2","100");

I use

request.addProperty("arg0","NSE");
request.addProperty("arg1",new Integer(0));
request.addProperty("arg2",new Integer(1000));

also this link helped me.

also before asking this question I was facing some problem that the Simulator was not recognizing a Library. It shows error message something like "there is no library Ksoap2_j2me.jar" - resolved from this link.

Sorry for poor English but I think this can save time of some other developer.

OTHER TIPS

It's hard to tell from what you're posted, but my guess is that you're having some kind of network problem. I'm guessing that you initialize result = null;, and then your call to ht.call() throws an IOException, leaving result null.

You're using ksoap2, which is a library written for generic J2ME clients. However, BlackBerry networking doesn't work exactly like all other J2ME platforms.

You are controlling the BlackBerry network transport with your connection params string, which is hardcoded:

private static final String CONNECTION_PARAMS = ";deviceside=true";

Unfortunately, this string suffix may not be right for all network conditions (or any, if you don't have device APN settings correct).

I think you have a couple choices:

1. Connection Suffix Strings

You can try dynamically choosing the right suffix string, depending on conditions when your app runs. This can allow the device, for example, to connect via Wi-Fi if it's available, or via BES if that's available. Developers new to BlackBerry may be surprised that app code needs to worry about this (read here for more, or watch this).

If you want to simply replace CONNECTION_PARAMS with a dynamic string, you might check out the implementation here.

2. ConnectionFactory

In OS 5.0, BlackBerry added the ConnectionFactory class, which was a big improvement over the old way of having to assemble connection strings. If you only need to support OS 5.0 and greater, you might choose to rewrite the code to use ConnectionFactory.

Since you have access to the ksoap source code, you could change it. It looks like the connection code is in ServiceConnectionMidp.java:

public ServiceConnectionMidp(String url) throws IOException {
    connection = (HttpConnection) Connector.open(url, Connector.READ_WRITE, true);
}

Instead of attaching connection parameters to the url passed to this class, you could change the class to get the connection from a ConnectionFactory, customized to support the network transports you want.

Doing this means that if you ever want to update your code to use a new version of ksoap2, you'll need to make these modifications again. However, given the future of BlackBerry Java, that seems like a reasonable compromise to make.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top