Mail Archive Home | enhydra List | Febuary 2004 Index
| <-- Date Index --> | <-- Thread Index --> |
Hi there,I just thought I would share some source code with you. I have managed to get KSOAP and MIDP communicating with a .NET XML web service. I have noticed that some programmers have tried unsucessfully to do this. Anyways, it can be done.
cheers
Trent Mifsud
Monash University
/*
* SOAPMIDlet.java
*
* Created on 18 February 2004, 14:13
*/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import org.ksoap.*;
import org.kxml.*;
import org.ksoap.transport.*;
public class SOAPMIDlet extends MIDlet implements CommandListener {
private Command exitCommand; // The exit command
private Command connectCommand; private Display display; // The display for this MIDlet private Form mainForm;public SOAPMIDlet() {
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.SCREEN, 2);
connectCommand = new Command("Connect", Command.SCREEN, 3);
mainForm = new Form ("SOAP calls");
}
/**
* Start up the Hello MIDlet by creating the TextBox and associating
* the exit command and listener.
*/
public void startApp() {
mainForm.addCommand(exitCommand);
mainForm.addCommand(connectCommand);
mainForm.setCommandListener(this);
display.setCurrent(mainForm);
}
/**
* Pause is a no-op since there are no background activities or
* record stores that need to be closed.
*/
public void pauseApp() {
}
/**
* Destroy must cleanup everything not handled by the garbage collector.
* In this case there is nothing to cleanup.
*/
public void destroyApp(boolean unconditional) {
}
/*
* Respond to commands, including exit
* On the exit command, cleanup and notify that the MIDlet has been
destroyed.
*/
public void commandAction(Command c, Displayable s) {
if (c == exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
if (c == connectCommand)
{
try {
HttpTransport transport = null;
SoapObject soap = new
SoapObject("http://tempuri.org","HelloWorld");
transport = new HttpTransport();
transport.setUrl("http://localhost/WSHello/Service1.asmx");
transport.setSoapAction("http://tempuri.org/HelloWorld");
transport.debug = true;
java.lang.Object o = transport.call(soap); // <----- this
StringItem item = new StringItem("SOAP result", o.toString());
mainForm.append(item);
display.setCurrent(mainForm);
}
catch (Exception e) {
e.printStackTrace ();
}
}
}
}
| <-- Date Index --> | <-- Thread Index --> |
Powered by MHonArc.
Copyright © 1999-2005, ObjectWeb Consortium | contact | webmaster.