Welcome!

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

Native Development

Reply
Highlighted
New Contributor
Posts: 8
Registered: ‎02-12-2013
My Device: all
My Carrier: ..

connecting to server glassfish (webservice)

hello,

Can u please help me,

i am trying to connect to webservice from my application but i couldn't establich the connection Smiley Sad please can someone help me where is the problem or give me a code to restart the connection.

the code that i used is:

package com.KsoapConnectionTest;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;
import org.xmlpull.v1.XmlPullParserException;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;

public class testMainScreen extends MainScreen {
private RichTextField textField;
private ButtonField srvButton = new ButtonField("Service Call");

public testMainScreen() {
super();
System.out.println("Adding text");
LabelField title = new LabelField("HelloWorld Sample",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
textField = new RichTextField("Hello World!");
add(textField);
System.out.println("Added text");

srvButton.setChangeListener(listenerSrvButton);
add(srvButton);

}
FieldChangeListener listenerSrvButton = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
String serviceUrl = "http:/xxxxxxxxxxxx?wsdl";
String serviceNamespace = "http://WS/";
String soapAction = "http://WS/getActiveStates";
String serviceMethod = "getActiveStates";//getAboutUsContent

 

HttpTransport ht = new HttpTransport(serviceUrl);


ht.debug = true;
ht.setXmlVersionTag(" version=\"1.0\" encoding=\"UTF-8\"?>");

SoapObject rpc = new SoapObject(serviceNamespace, serviceMethod);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

// envelope.setOutputSoapObject(rpc);

System.out.println("Created envelope");
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
/*
* envelope.encodingStyle = SoapSerializationEnvelope.ENC;
* envelope.encodingStyle = SoapSerializationEnvelope.XSI;
*/

// rpc.addProperty("Celsius", "12");
String result = "";
try {

ht.call(soapAction, envelope);
result = (envelope.getResponse()).toString();
System.out.println(result);// for debugging
net.rim.device.api.ui.component.Dialog.alert(envelope.getResponse().toString());

} catch (XmlPullParserException ex) {
String msg = ex.toString();
System.out.println(msg);
} catch (Exception ex) {
System.out.println("i am here in catch");
System.out.println(ex.getMessage());
// String msg = ex.toString();

}
textField.setText(result);
// ((HelloWorldScreen)this.getActiveScreen()).setScre enTest(result);
}
};
/*
* public void setScreenTest(String text) { textField.setText(text); }
*/

public boolean onClose() {
Dialog.alert("Goodbye!");
System.exit(0);
return true;
}

}

 

The problem is when the debug inter the call zone so please can someone tell me how to connect ? or give me another methos? thank you so much