【发布时间】:2012-11-25 08:16:31
【问题描述】:
我为调用网络服务创建了一个简单的类
public class CallSoap {
public final String SOAP_ACTION = "http://tempuri.org/Add";
public final String OPERATION_NAME = "Add";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://localhost:41614/Service1.asmx";
public CallSoap()
{
}
public String Call(int a,int b)
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
request.addProperty("a",a);
request.addProperty("b",b);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransport httpTransport = new HttpTransport(SOAP_ADDRESS);
Object response=null;
try
{
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
}
catch (Exception exception)
{
response=exception.toString();
}
return response.toString();
}
}
这是我的Activity点击方法
public void clickData(View v)
{
//Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText et=(EditText) findViewById(R.id.editText1);
EditText et2=(EditText) findViewById(R.id.editText2);
TextView tv=(TextView) findViewById(R.id.textView1);
int a=Integer.parseInt(et.getText().toString());
int b=Integer.parseInt(et2.getText().toString());
CallSoap cs=new CallSoap();
tv.setText(cs.Call(a, b));
}
出现错误“不幸的是 App1 已停止”。请帮帮我..
【问题讨论】:
-
发布 logcat 详细信息。也看看链接。这应该可以帮助你。 youtube.com/watch?v=v9EowBVgwSo
-
你在用什么
android OS?我猜是NetworkOnMainThreadException的情况@ -
你能记录和分享异常[使用Logcat -> log.e(tag, message)]吗?
-
我用的是安卓4.2版本
标签: android asp.net web-services android-ksoap2