我是 android 开发新手,我正在尝试通过 UltiDiv 访问本地托管的 Web 服务,当我运行应用程序时它给了我胎儿异常,我在 android 清单中添加了 INTERNET 和 NETWORK_STATE 权限,但它仍然相同。Web 服务名称是 connecto,方法名称是 DbRead,并采用字符串 phone
// here is the code
package finalProject.test.webService;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.*;
import android.util.Log;
import android.widget.TextView;
import android.os.Bundle;
public class FinalWebServiceDemoActivity extends Activity {
// some parameters regarding your web-service to be invoked
private static final String SOAP_ACTION = "http://tempuri.org/connecto";
private static final String METHOD_NAME = "DbRead";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.168.1.8:8080/connecto.asmx";
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView)findViewById(R.id.text1);
call();
}
public void call()
{
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("phone","1234");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
String strRes = result.toString();
tv.setText(strRes);
} catch (Exception e) {
tv.setText("Exception...");
Log.i("exception", e.toString());
StackTraceElement elements[] = e.getStackTrace();
for (int i = 0, n = elements.length; i < n; i++) {
Log.i("File", elements[i].getFileName());
Log.i("Line", String.valueOf(elements[i].getLineNumber()));
Log.i("Method", elements[i].getMethodName());
}
}
}
}