我需要从 url 调用 web 服务。我在文本框中输入了 no 我应该在文本框中输入的输出。请帮助我修复错误。这是我的java代码。
MainActivity.java
public class MainActivity extends Activity {
Button b;
TextView tv;
EditText et;
String editText;
String displayText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et = (EditText) findViewById(R.id.editText1);
tv = (TextView) findViewById(R.id.tv_result);
b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (et.getText().length() != 0 && et.getText().toString() != "") {
editText = et.getText().toString();
AsyncCallWS task = new AsyncCallWS();
task.execute();
} else {
tv.setText("Please enter number");
}
}
});
}
private class AsyncCallWS extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
displayText = ser.invokeiop(editText,"hello");
return null;
}
}
}
ser.java
public class ser {
private static String NAMESPACE = "http://tempuri.org/";
private static String URL = "http://my url";
private static String SOAP_ACTION = "srvice";
public static String invokeiop(String name, String webMethName) {
String resTxt = null;
SoapObject request = new SoapObject(NAMESPACE, webMethName);
PropertyInfo iop = new PropertyInfo();
iop.setName("name");
iop.setValue(name);
//iop.setType(String.class);
request.addProperty(iop);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION+webMethName, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
resTxt = response.toString();
} catch (Exception e) {
e.printStackTrace();
resTxt = "Error occured";
}