Ibraheem Osama Mohamed (ابراهيم اسامه محمد)

Welcome to my blog :)

Android and KSOAP

leave a comment »

Consuming a web service in a .net language is very easy. so if you want to consume a web service in android that will be hard ?? of course no but you must know very well what will you do exactly
Lets start This is the Code for consuming the web service we used a library KSOAP2 for SE not FOR ME
if you are consuming it using a WCF so you must say the it is a .net “every thing is in the code”
also if you typed the url like that http://10.0.2.1:2612/Service1.svc you’ll get an error cause the android emulator is using this port so use http://10.0.2.2:2612/Service1.svc change the 1 in the last of the port number to 2 🙂
the last thing you must specify the method name as you wrote it in the Web Service ex : my method was taking a string m so I wrote in the addProperty(“m”,”//here the object you want to send”)
Good luck 🙂 

try {
    // TODO Auto-generated method stub
    
    SoapObject request = new SoapObject("http://tempuri.org/""GetCoursesInfos");
    request.addProperty("m","courses");
    
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet=true;
    envelope.setOutputSoapObject(request);
    
    
    HttpTransportSE http = new HttpTransportSE("http://10.0.2.2:2612/Service1.svc");
    
      http.call("http://tempuri.org/IService1/GetCoursesInfos", envelope);
      
      Object result= (Object)envelope.getResponse();
      message=result.toString();
      

      
    catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      Log.d(“1”“first exe”);
      txt.setText(e.getMessage());
    
    }

Ibraheem Osama Mohamed
Twitter : @IbraheemOsamaMo 

Advertisements

Written by Ibraheem Osama Mohamed

May 9, 2012 at 10:27 am

Posted in android, java, Ksoap, web service

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: