我被卡住了,不知道该怎么办?当我尝试调用 Web 服务时,出现错误,例如找不到 AndroidHttpTransport 类。我想从 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();`
` }`
`}`
`});`
`}`
`}`