2013-02-11 18 views
0

我被卡住了,不知道該怎麼辦?當我嘗試調用Web服務時,出現錯誤,例如AndroidHttpTransport類未找到。我想要從Web服務的結果,並希望如何調用Web服務並從中檢索結果並將其顯示給應用程序

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();` 
      ` }` 
      `}` 
     `});` 
    `}` 
`}` 
+0

需要看你的代碼 – Satya 2013-02-11 15:32:31

+0

我貼我的代碼plz幫助我在這 – Viraj 2013-02-11 15:56:35

回答

0

,如果你需要通過下面的例子來學習,這裏有一對夫婦展示瞭如何列出的ListView結果以及如何使用HTTP/REST調用API的。 ..

List

REST

相關問題