JSR 172,Web Services API , extends the J2ME platform to support web services. This webservice api consist of 2 optional packages: "Java API for Remote Method Invocations" and "Java API for XML Processing".

Below is a simple illustration of webservice using differnt xml parsers.

 import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

import org.ksoap.*;
import org.kobjects.serialization.*;
import org.kxml.*;
import org.kxml.io.*;
import org.kxml.parser.*;

public class HelloWorld extends MIDlet implements CommandListener {
    
    private Display display;
    private Command doneCommand;
    private TextField textField;
    
    public HelloWorld() throws Exception {
        display = Display.getDisplay(this);
        doneCommand = new Command("DONE", Command.CANCEL, 1);
    }
    
    private String soapMesg =
            "<SOAP-ENV:Envelope " +
            "xmlns:SOAP-ENV=\"http://www.w3.org/2001/12/soap-envelope\" " +
            "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
            "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
            "<SOAP-ENV:Body>" +
            "<message xsi:type=\"xsd:string\">Hello World</message>" +
            "<message02 xsi:type=\"xsd:string\">unreachable</message02>" +
            "</SOAP-ENV:Body>" +
            "</SOAP-ENV:Envelope>";
    
    private String soapRespMesg =
            "<SOAP-ENV:Envelope " +
            "xmlns:SOAP-ENV=\"http://www.w3.org/2001/12/soap-envelope\" " +
            "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
            "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
            "<SOAP-ENV:Body>" +
            "<result>" +
            "<message xsi:type=\"xsd:string\">Hello World</message>" +
            "</result>" +
            "</SOAP-ENV:Body>" +
            "</SOAP-ENV:Envelope>";
    
    private String processMesg(String mesg) throws Exception {
        ByteArrayInputStream bis = new ByteArrayInputStream(mesg.getBytes());
        InputStreamReader reader = new InputStreamReader(bis);
        XmlParser xp = new XmlParser(reader);
        
        SoapEnvelope envelope = new SoapEnvelope(new ClassMap(Soap.VER12));
        envelope.parse(xp);
        
        return (String) envelope.getBody();
    }
    
    private String processRespMesg(String mesg) throws Exception {
        ByteArrayInputStream bis = new ByteArrayInputStream(mesg.getBytes());
        InputStreamReader reader = new InputStreamReader(bis);
        XmlParser xp = new XmlParser(reader);
        
        SoapEnvelope envelope = new SoapEnvelope(new ClassMap(Soap.VER12));
        envelope.parse(xp);
        
        return (String) envelope.getResult();
    }
    
    public void startApp() {
        String mesg;
        Form form = new Form("Hello World Example");
        try {
            mesg = processMesg(soapMesg);
        } catch (Exception e) {
            mesg = "parsing failed";
            e.printStackTrace();
        }
        form.append(new StringItem("SoapMesg", mesg));
        try {
            mesg = processRespMesg(soapRespMesg);
        } catch (Exception e) {
            mesg = "parsing failed";
            e.printStackTrace();
        }
        form.append(new StringItem("SoapRespMesg", mesg));
        
        form.addCommand(doneCommand);
        form.setCommandListener((CommandListener) this);
        display.setCurrent(form);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    
    public void commandAction(Command command, Displayable screen) {
        if (command == doneCommand) {
            destroyApp(false);
            notifyDestroyed();
        }
    }
}