| |
"Mobile Web Services with kSOAP"
Vol. 7, Issue 10, p. 56
Listing 1: SOAP request
POST /ws/taxCalc.php HTTP/1.1
SOAPAction: urn:soap-whytewolf-ca:taxcalc#taxCalc
Content-Type: text/xml
Content-Length: 557
User-Agent: kSOAP/1.0
Host: www.whytewolf.ca
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body SOAP ENV:encodingStyle="http:
//schemas.xmlsoap.org/soap/encoding/">
<taxCalc xmlns="urn:soap-whytewolf-ca:taxcalc" id="o0" SOAP-ENC:root="1">
<rate xmlns="" xsi:type="xsd:string">7</rate>
<sub xmlns="" xsi:type="xsd:string">856</sub>
</taxCalc>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Listing 2: SOAP response
HTTP/1.1 200 OK
Date: Mon, 12 Aug 2002 01:31:10 GMT
Server: Apache/1.3.14 (Unix) mod_perl/1.24 PHP/4.0.6 FrontPage/4.0.4.3
mod_ssl/2.7.1 OpenSSL/0.9.6
X-Powered-By: PHP/4.0.6
Status: 200 OK
Connection: Close
Content-Length: 510
Content-Type: text/xml; charset=UTF-8
<?xml version="1.0"?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:si="http://soapinterop.org/xsd">
<SOAP-ENV:Body>
<taxCalcResponse>
<noname xsi:type="xsd:float">915.92</noname>
</taxCalcResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Listing 3: SOAP fault
HTTP/1.1 200 OK
Date: Mon, 12 Aug 2002 01:32:12 GMT
Server: Apache/1.3.14 (Unix) mod_perl/1.24 PHP/4.0.6 FrontPage/4.0.4.3
mod_ssl/2.7.1 OpenSSL/0.9.6
X-Powered-By: PHP/4.0.6
Status: 500 Internal Server Error
Connection: Close
Content-Length: 607
Content-Type: text/xml; charset=UTF-8
<?xml version="1.0"?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:si="http://soapinterop.org/xsd">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>Client</faultcode>
<faultactor></faultactor>
<faultstring>Must supply a non-zero subtotal.</faultstring>
<faultdetail></faultdetail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Listing 4: getTax() function
private void getTax() {
amount = input.getString();
try{
SoapObject client = new
SoapObject("urn:soap-whytewolf-ca:taxcalc","taxCalc");
client.addProperty("rate",rate);
client.addProperty("sub",amount);
HttpTransport ht = new
HttpTransport("http://www.whytewolf.ca/ws/taxCalc.php",
"urn:soap-whytewolf-ca:taxcalc#taxCalc");
taxMsg.setText("$" + ht.call(client));
}
catch (SoapFault sf){
taxMsg.setLabel("FAULT:\n");
String faultString = "Code: " + sf.faultcode + "\nString: "
+ sf.faultstring;
taxMsg.setText(faultString);
} catch (Exception e) {
e.printStackTrace();
taxMsg.setLabel("ERROR:\n");
taxMsg.setText(e.toString());
}
getForm.addCommand(backCommand);
getForm.setCommandListener(this);
display.setCurrent(getForm);
}
|
|