0

I am stuck and not getting what to do? When I try to call web service I got error such as AndroidHttpTransport class not found. I want to retrieve results from web service and want

to display into my android app. Plz help me on this...
`import org.ksoap2.SoapEnvelope;`
`import org.ksoap2.serialization.SoapObject;`
`import org.ksoap2.serialization.SoapSerializationEnvelope;`
`import org.ksoap2.transport.AndroidHttpTransport;`

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

`public class SoapWebServiceActivity extends Activity {`
 `   private static final String SOAP_ACTION = "http://tempuri.org/Select";`
  `  private static final String METHOD_NAME = "Select";`
   ` private static final String NAMESPACE = "http://tempuri.org/";`
    `private static final String URL = "http://www.xyz.com:50233/Service1.asmx";`

    `private SoapObject resultRequestSOAP = null;`

    /** Called when the activity is first created. */`
    `@Override`
    `public void onCreate(Bundle savedInstanceState) {`
     `   super.onCreate(savedInstanceState);`
      `  //TextView tv = new TextView(this);`
       ` setContentView(R.layout.main);`
        `Button cmd_submit = (Button) findViewById(R.id.widget35);`
        `cmd_submit.setOnClickListener(new OnClickListener() {`

         `   @Override`
          `  public void onClick(View arg0) {`
           `     AndroidHttpTransport androidHttpTransport =`
            `         new AndroidHttpTransport(URL);`
             `   try {`
              `      /* Get what user typed to the EditText. */`
               `     String searchNameString =`
                `           ((EditText) findViewById(R.id.widget42))`
                 `           .getText().toString();`
`
 `                   SoapObject request = new SoapObject(NAMESPACE,`
  `                         METHOD_NAME);`
   `                 // Add the input required by web service`
    `                request.addProperty("sPUID", searchNameString);`
     `               SoapSerializationEnvelope envelope =`
      `                     new SoapSerializationEnvelope(SoapEnvelope.VER11);`
       `             envelope.setOutputSoapObject(request);`
        `            // Make the soap call.`
         `           androidHttpTransport.call(SOAP_ACTION, envelope);`
`
 `                   // Get the SoapResult from the envelope body.`
  `                  resultRequestSOAP = (SoapObject) envelope.bodyIn;`
`
 `                   SoapObject nameResult = (SoapObject) resultRequestSOAP`
  `                          .getProperty(0);`
   `                 int count = nameResult.getPropertyCount();`
    `                StringBuilder stringBuilder = new StringBuilder();`
     `               /*`
      `               * Retrieve one property from the complex SoapObject`
       `              * response`
        `             */`
         `           for (int i = 0; i < count - 1; i++) {`
          `              SoapObject simpleSuggestion = (SoapObject) nameResult`
           `                     .getProperty(i);`
            `            stringBuilder.append(simpleSuggestion.getProperty(`
             `                   "representation").toString());`
              `          stringBuilder.append("\n");`
               `     }`
                `    String temp = stringBuilder.toString();`

`                    /** Show the suggestions in a text area field called`
 `                   * lblStatus */`
  `                  ((TextView) findViewById(R.id.widget32)).setText(temp`
   `                         .toString());`
    `                ((TextView) findViewById(R.id.widget33)).setText(temp`
     `                       .toString());`
      `              ((TextView) findViewById(R.id.widget34)).setText(temp`
       `                     .toString());`
        `            
         `       } catch (Exception aE) {`
          `          System.out.println(aE.toString());`
           `         aE.printStackTrace();`
            `    }`
            `}`
        `});`
    `}`
`}`
Satya
  • 8,693
  • 5
  • 34
  • 55
Viraj
  • 3
  • 1
  • 4

1 Answers1

0

if you need to learn by following examples, here are a couple that show how to list the results in ListView and how to use http/REST to call API's...

List

REST

Community
  • 1
  • 1
Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43