2006-06-06 06:21:00 UTC
Thank you. It works great.
Here is very easy MIDP2 Midlet based on your code.
Tested with emulator from Netbeans Mobile Pack and Nokia 6230i (on Nokia is small display -> only part of output is displayed ).
Leos
-------------------------------------------------
/*
* StadiumMidlet.java
* used with ksoap2-j2me-core-2.1.0.jar
*/
package cz.qds.midlet;
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;
/**
*
* @author lur
* @version
*/
public class StadiumMidlet extends MIDlet implements CommandListener
{
Display display = null;
// screen #1
TextBox screen1 = null;
Command screen1cancel = null;
Command screen1query = null;
// screen #2
List screen2 = null;
Command screen2ok = null;
class ConnectionThread extends Thread
{
public void run()
{
query();
}
}
private void query()
{
String NAMESPACE = "
http://www.dataaccess.nl/wk2006";
String URL = "
http://www.dataaccess.nl/wk2006/footballpoolwebservice.wso";
screen2.deleteAll(); // delete all items from List
SoapObject request = new SoapObject(NAMESPACE, "StadiumNames");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransport ht = new HttpTransport(URL);
try
{
ht.call("StadiumNames", envelope);
if (envelope.getResponse()==null)
{
throw new Exception("Communication Error.");
}
else
{
SoapObject response = (SoapObject) envelope.getResponse();
int numberOfStadiums = response.getPropertyCount();
for (int i = 0; i < numberOfStadiums; i++)
{
SoapPrimitive value = (SoapPrimitive) response.getProperty(i);
screen2.append( value.toString(), null );
}
}
}
catch (Exception e)
{
Alert alert = new Alert(e.getMessage());
alert.setTimeout(5000);
alert.setString(e.toString());
display.setCurrent(alert, screen2);
}
}
private void createScreenForm()
{
String value = "";
value += "This WS client returns all stadiums in Germany for FIFA WC2006.";
value += "\n";
value += "\n";
value += "Press Search for connection to remote webservice...";
value += "\n";
value += "...and wait some time...";
screen1 = new TextBox("Studiums WC2006",value,255,TextField.PLAIN | TextField.UNEDITABLE);
screen1query = new Command("Search", Command.OK, 0);
screen1cancel = new Command("Cancel", Command.CANCEL, 1);
screen1.addCommand( screen1cancel );
screen1.addCommand( screen1query );
screen1.setCommandListener( this );
}
private void createScreenResult()
{
String value = "";
screen2 = new List("Studiums WC2006",List.EXCLUSIVE);
screen2ok = new Command("OK", Command.SCREEN, 0);
screen2.addCommand( screen2ok );
screen2.setCommandListener( this );
}
public StadiumMidlet()
{
createScreenForm();
createScreenResult();
}
public void startApp()
{
display = Display.getDisplay(this);
display.setCurrent( screen1 );
}
public void pauseApp()
{
notifyPaused();
}
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
public void commandAction(Command command, Displayable displayable)
{
if (command==screen1query)
{
ConnectionThread t = new ConnectionThread();
t.start();
display.setCurrent( screen2 );
}
if (command==screen1cancel)
{
destroyApp(true);
}
if (command==screen2ok)
{
destroyApp(true);
}
}
}