Basic "hello world" test

<[email protected]> Tue, 26 Nov 2002 9:11:06 +0000
Newsgroups gmane.comp.java.enhydra.ksoap,gmane.spam.detected
Message-ID <20021126091106.KKUA5142.fep02-svc.ttyl.com@localhost>
Hi, and sorry for the long post...
I have a console java app which just does a simple "ping" and can't get it to work using kSoap. As its my first I probably have the params screwed ;-)

The error I get is 

ParseException: unexpected: StartTag <HTML> line: -1 attr: null @-1:-1
If its relevant, the server uses Apache soap (not axis). Can anyone spot whats wrong please?

Heres the console java version:

public class ping {
    public static void main (String[] args) {
        try {

	    URL url = new URL("http://service.srxml.org/servlet/rpcrouter");
            SOAPHTTPConnection st = new SOAPHTTPConnection();

	    Call call = new Call();
            call.setSOAPTransport(st);

	    call.setTargetObjectURI("urn:pingService");

	    call.setMethodName("process");

	    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

            Response resp = null;
            try {
                resp = call.invoke(url, "");
            } catch(Exception e) {
                System.err.println(e.toString());
            }

            Object value = null;

            if (!resp.generatedFault()) {
                Parameter ret = resp.getReturnValue();
                value = ret.getValue();
            } else {
                Fault fault = resp.getFault();
                System.err.println("SOAP call raised fault code:"
	            +fault.getFaultCode()
                    +" Text:"+ fault.getFaultString());
            }

            System.out.println("Return value is "+value);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

And heres my attempt at the kSOAP version:

public class Ping extends MIDlet implements CommandListener {

    static final String serviceNamespace = "http://service.srxml.org/namespace/";

    Form mainForm = new Form ("Ping");
    StringItem resultItem = new StringItem ("", "");
    Command getCommand = new Command ("Get", Command.SCREEN, 1);

    public Ping () {
	mainForm.append (resultItem);
	mainForm.addCommand (getCommand);
	mainForm.setCommandListener (this);
    }

    public void startApp () {
	Display.getDisplay (this).setCurrent (mainForm);
    }

    public void pauseApp () {
    }

    public void destroyApp (boolean unconditional) {
    }

    public void commandAction (Command c, Displayable d) {

        String resultStr = "Result: ";
	HttpTransport transport = new HttpTransport
	    ("http://service.srxml.org/servlet/rpcrouter/", "pingService");

	transport.debug = true;

	try {
	    System.out.println("Creating request object");
	    resultItem.setText (resultStr);

	    SoapObject request = new SoapObject (serviceNamespace, "process");

	    ClassMap classMap = new ClassMap(true);

	    transport.setClassMap (classMap);

	    resultStr += " calling SOAP method";
	    resultItem.setText (resultStr);
	    System.out.println("Invoking...");
	    String result = transport.call (request).toString ();

	    resultStr += result;
	    resultItem.setLabel ("Result :");
	    resultItem.setText (resultStr);
	}
	catch (Exception e) {
	    resultItem.setLabel ("Error:");
	    resultItem.setText (resultStr+ " "+e.toString ());
	    System.out.println("Error: "+e.toString());
	}
    }
}


_______________________________________________________________________
Freeserve AnyTime, only £13.99 per month with one month's FREE trial!
For more information visit http://www.freeserve.com/time/ or call free on 0800 970 8890