pata
pata

Reputation: 989

BlackBerry consume wcf

I am working with OS 5.0 and I am trying to get some info from a wcf. On the emulator it works like a champ, but on a device, with wifi connected, I get the error:

APN is not specified

my code:

    HttpConnection con = null;
    InputStream is = null;

    try {
        con = (HttpConnection) Connector.open(url);
        final int responseCode = con.getResponseCode();
        if (responseCode != HttpConnection.HTTP_OK) {
            System.out.println(responseCode);
        }
        is = con.openInputStream();
        byte[] responseData = new byte[10000];
        int length = 0;
        StringBuffer rawResponse = new StringBuffer();
        while (-1 != (length = is.read(responseData))) {
            rawResponse.append(new String(responseData, 0, length));
        }
        final String result = rawResponse.toString();
        _labelField.setText(result);

    } catch (final Exception ex) {
        System.out.println(ex.getMessage());
        _labelField.setText(ex.getMessage());

    } finally {
        try {
            is.close();
            is = null;
            con.close();
            con = null;
        } catch (Exception e) {
        }
    }

Upvotes: 2

Views: 213

Answers (1)

Kiran Kuppa
Kiran Kuppa

Reputation: 1457

Check this article "Different ways to make HTTP Socket Connection". This article would help you understand how to make network connections if you are on BES network or BIS or WiFi or 3G network etc.

Getting back to your problem, if you want to connect through Wi-Fi, you will need to modify your connection url. Replace the following:

con = (HttpConnection) Connector.open(url);

With this:

con = (HttpConnection) Connector.open(url+";interface=wifi");

Now it would work on device with Wi-Fi connectivity.

Upvotes: 3

Related Questions