[问题]用AndroidAPP呼叫WebService(已解决)!!!

楼主: aallens (ALLENS)   2014-06-04 08:26:40
各位大大好~
小弟想试着用AndroidAPP写一个呼叫自己另外用.Net架设的WebService
但是似乎都没有反应~
不知道是否哪边出问题了?
下面的Code e.getMessage()都是空值~
所以我才又加一行~把button.text="xxx"
最后运行结果~Button的text都会变成xxx~表示真的有进入exception~
Code如下:
public void doSomething(View v)
{
Button btn = null;
btn=(Button)findViewById(R.id.button1);
String NAMESPACE = "http://tempuri.org/";
String URL = "http://127.0.0.1:2282/service1.asmx";
String SOAP_ACTION = "http://tempuri.org/HelloWorld";
String METHOD_NAME="HelloWorld";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
btn.setText(result.toString());
}
catch(Exception e)
{
e.printStackTrace();
btn.setText(e.getMessage());
btn.setText("xxx");
}
}
作者: kewang (652公共汽车)   2014-06-04 08:35:00
ip问题
楼主: aallens (ALLENS)   2014-06-04 09:08:00
ip改成了192.168.x.x的~也不行~
作者: chiel (All 喷 将!!)   2014-06-04 09:30:00
你用模拟器跑吗?
作者: slemonade (淳)   2014-06-04 12:27:00
看看网段是否一样,我常没同网段就在测(残唸
楼主: aallens (ALLENS)   2014-06-04 14:35:00
我用手机跑的~~~
作者: Lycca (Lycca)   2014-06-04 14:47:00
Internet permission?
楼主: aallens (ALLENS)   2014-06-04 15:05:00
哪个也加入了~主要在Try的第一行就跳到catch了~Exception类别是Android.os.NetworkOnMainThreadException

Links booklink

Contact Us: admin [ a t ] ucptt.com