I use ksoap with web service in Andrid.
java code:

package com.WsReader;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Button;

// ksoap2 import
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.serialization.PropertyInfo;

public class WsReader extends Activity {

        private static final String SOAP_ACTION = "http://tempuri.org/
HelloWorld";//"AddIntegers";
    private static final String METHOD_NAME =
"HelloWorld";//"AddIntegers";
    private static final String NAMESPACE = "http://tempuri.org/";;
    private static final String URL = "http://192.168.100.123/
AsapWebRun/AsapService/wf.asmx";//"http://wiki.tuxpan.com:8069/axis2/
services/Simple";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(android.R.style.Theme_Dialog);
        setContentView(R.layout.main);

        // cmdCalculate button
        final Button cmdcal = (Button) findViewById
(R.id.cmdCalculate);
        cmdcal.setOnClickListener(new Button.OnClickListener(){
                public void onClick(View v){
                        ((TextView)findViewById(R.id.lblStatus)).setText("...
Invoking Web Service ...");
                        String 
stA=((EditText)findViewById(R.id.numberA)).getText
().toString();
                        String 
stB=((EditText)findViewById(R.id.numberB)).getText
().toString();
                        /*
                        Integer a=null;
                        Integer b=null;
                        try
                        {
                                a=Integer.valueOf(stA);
                                b=Integer.valueOf(stB);
                        }
                        catch(Exception ex){}
                        if(a==null || b==null){
                                
((TextView)findViewById(R.id.lblStatus)).setText("Only
Integer numbers please...");
                        }
                        */
                        // ksoap
                        SoapObject request=new 
SoapObject(NAMESPACE,METHOD_NAME);
                        /*
                        SoapObject inAddIntegers=new SoapObject
(NAMESPACE,"GetAuthorizationTicket");
                        inAddIntegers.addProperty("userID", stA);
                        inAddIntegers.addProperty("userPass", stB);
                        
request.addProperty("GetAuthorizationTicket",inAddIntegers);
                        */
                        SoapSerializationEnvelope envelope=new
SoapSerializationEnvelope(SoapEnvelope.VER11);
                        envelope.dotNet=true;
                        envelope.setOutputSoapObject(request);
                        AndroidHttpTransport androidHttpTransport=new
AndroidHttpTransport(URL);
                        try
                        {
                                androidHttpTransport.call(SOAP_ACTION, 
envelope);
                                Object result=envelope.getResponse();
                                ((TextView)findViewById(R.id.lblStatus)).setText
(result.toString());
                        }
                        catch(Exception ex){
                                
((TextView)findViewById(R.id.lblStatus)).setText("Error:
"+ex.getClass().getName()
                                                +":"+ex.getMessage());

                        }
                }
        });
    }// end of onCreate
}// end of class WsReader


=======================================

.net web service code:
---------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;


[WebService(Namespace = "http://tempuri.org/";)]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
// [System.Web.Script.Services.ScriptService]
public class wf : System.Web.Services.WebService
{

    public wf()
    {

    }

    [SoapRpcMethod(), WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }
}

//////////////////////////////////////////////////////////////////////////////

when I run the application in emulator,It cannot successful.
then I write a normal java application

// ksoap2 import
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.serialization.PropertyInfo;

public class WfReader
{
        private static final String SOAP_ACTION = "http://tempuri.org/
HelloWorld";//"AddIntegers";
    private static final String METHOD_NAME =
"HelloWorld";//"AddIntegers";
    private static final String NAMESPACE = "http://tempuri.org/";;
    private static final String URL = "http://192.168.100.123/
AsapWebRun/AsapService/wf.asmx";//"http://wiki.tuxpan.com:8069/axis2/
services/Simple";

        public static void main(String[] args)
        {
                System.out.println("Hello World!");
                SoapObject request=new SoapObject(NAMESPACE,METHOD_NAME);
                /*
                SoapObject inAddIntegers=new SoapObject
(NAMESPACE,"GetAuthorizationTicket");
                inAddIntegers.addProperty("userID", stA);
                inAddIntegers.addProperty("userPass", stB);
                request.addProperty("GetAuthorizationTicket",inAddIntegers);
                */
                SoapSerializationEnvelope envelope=new SoapSerializationEnvelope
(SoapEnvelope.VER11);
                envelope.dotNet=true;
                envelope.setOutputSoapObject(request);
                AndroidHttpTransport androidHttpTransport=new 
AndroidHttpTransport
(URL);
                try
                {
                        androidHttpTransport.call(SOAP_ACTION, envelope);
                        Object result=envelope.getResponse();
                        System.out.println(result.toString());
                }
                catch(Exception ex){
                        System.out.println("error:");
                        System.out.println(ex.getMessage());
                }
        }
}


=====================================
run it ,the error is:

Hello World!
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/
commons/httpclient/methods/RequestEntity
        at org.ksoap2.transport.AndroidHttpTransport.getServiceConnection
(AndroidHttpTransport.java:89)
        at org.ksoap2.transport.AndroidHttpTransport.call
(AndroidHttpTransport.java:38)
        at WfReader.main(WfReader.java:31)
Caused by: java.lang.ClassNotFoundException:
org.apache.commons.httpclient.methods.RequestEntity
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        ... 3 more


why?????????????

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

Reply via email to