Hi christian110011,

for kSOAP, you have to do something like this :
// you have to download ksoap for j2me and extend it's
org.ksoap2.transport.Transport  and implement ServiceConnection, coz
it is built
// for j2me not Android, you can eaisly find these two on other android group

Thread t = new Thread()
                                {
                                        private static final String SOAP_ACTION 
= "addition";
                                        private static final String METHOD_NAME 
= "addition";
                                        private static final String NAMESPACE = 
"http://ws.apache.org/axis2";;

                                        // This is for service
deployed on Tomcat, for JBOSS Android is not working on my emulator

                                        private static final String URL =
"http://yourIP:8080/Axis2ServiceServer/services/CalcService";;
                                        Integer a = null;
                                        Integer b = null;

                                        @Override
                                        public void run()
                                        {
                                                String stA = ((EditText)
findViewById(R.id.EditText01)).getText().toString();
                                                String stB = ((EditText)
findViewById(R.id.EditText02)).getText().toString();
                                                SoapSerializationEnvelope 
envelope = null;
                                                try
                                                {
                                                        a = 
Integer.valueOf(stA);
                                                        b = 
Integer.valueOf(stB);
                                                        SoapObject request = 
new SoapObject(NAMESPACE,METHOD_NAME);
                                                        
request.addProperty("a", a);
                                                        
request.addProperty("b", b);
                                                        envelope = new 
SoapSerializationEnvelope(SoapEnvelope.VER11);
                                                        
envelope.setOutputSoapObject(request);
                                                        AndroidHttpTransport 
androidHttpTransport = new
AndroidHttpTransport(URL);
                                                        
androidHttpTransport.call(SOAP_ACTION, envelope);
                                                        Object result = 
envelope.getResponse();
                                                        KSoapClient.res = 
result.toString();
                                                }
                                                catch (NumberFormatException 
nfe)
                                                {
                                                        KSoapClient.res = "Only 
Integer numbers ";
                                                        Log.e("Input Error: ", 
nfe.getMessage());
                                                }
                                                catch (SoapFault sf)
                                                {
                                                        Log.e("Service Response 
Error, "+ sf.faultcode+":",
sf.faultstring);
                                                }
                                                catch (IOException ioe)
                                                {
                                                        Log.e("Service Response 
Error: ", ioe.getMessage());
                                                }
                                                catch (XmlPullParserException 
xppe)
                                                {
                                                        Log.e("Service Response 
Error: ", xppe.getMessage());
                                                }
                                        }
                                };
                                t.start();

And if you like to create your own SOAP Engine(Custom Parser will do),
you may do,


    public String serviceResponse(String a , String b)
    {
        String s=null;
                Integer ai = null;
                Integer bi = null;
        Document doc;
        try
        {
                DocumentBuilderFactory factory =
                        DocumentBuilderFactory.newInstance();
                        DocumentBuilder parser = factory.newDocumentBuilder();

                        ai = Integer.valueOf(a);
                        bi = Integer.valueOf(b);
                        doc = parser.parse(new
URL("http://192.168.1.101:8089/axis/Calc.jws?method=add&a="+a+"&b="+b).openConnection().getInputStream());
                        if(null!=doc.getElementsByTagName("soapenv:Envelope"))
                        if(null!=doc.getElementsByTagName("soapenv:Body"))
                        {       
                        if(null!=doc.getElementsByTagName("addReturn"))
                        {
                                 NodeList nl 
=doc.getElementsByTagName("addReturn");
                                 s=nl.item(0).getFirstChild().getNodeValue();
                        
                        }
                        else // not working due to IO error
                        {
                                
if(null!=doc.getElementsByTagName("soapenv:Fault"))
                                {
                                        s = "Unable to get Service";
                                }
                                else
                                {
                                        
                                }
                        }
                        }       
                } catch (ParserConfigurationException e) {
                        
                        Log.e("Error", e.getMessage());
                } catch (FactoryConfigurationError e) {
                        
                        Log.e("Error", e.getMessage());
                } catch (SAXException e) {
                        
                        Log.e("Error", e.getMessage());
                } catch (MalformedURLException e) {
                        
                        Log.e("Error", e.getMessage());
                } catch (IOException e) {
                        
                        Log.e("Error", e.getMessage());
                }
                catch(Exception e)
                {
                        if (ai == null || bi == null) {
                                s = "Addition service is only for integers!!";
                        }
                }
                return s;
On Thu, Oct 16, 2008 at 6:07 PM, christian110011
<[EMAIL PROTECTED]> wrote:
>
> hi all
> does anybody know how to call a soap web service from an android
> application (ie. the android app is the web service client)? which
> approaches are the best? any alternatives?
> thx :-)
> regards, christian
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to