Android webservice asp .asmx

时间:2012-08-31 10:19:14

标签: java android android-service ksoap2

我尝试通过ksoap2连接Android - webservice。我有个问题。当我在Java中运行一个Console应用程序时,它运行正常。但是,当我将此代码复制到Android时,它会出错:

  

“Java.Net.UnknowHostException.jeryservice.somee.com”。

我的代码:

String NAMESPACE = "http://jeryservice.somee.com/";
String URL = "http://jeryservice.somee.com/myservice/Service1.asmx";
String SOAP_ACTION = "http://jeryservice.somee.com/test";
SoapObject request= null;
String rs="";
request=new SoapObject(NAMESPACE,"test");
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
request.addProperty("name", " Jery ok man");
envelope.setOutputSoapObject(request);
HttpTransportSE transp=null;
transp=new HttpTransportSE(URL);
try {
  transp.call(SOAP_ACTION, envelope);
  Object rsl=envelope.getResponse();
  rs=rsl.toString();
  Toast.makeText(getApplicationContext(),"ok-> "+ rs, Toast.LENGTH_SHORT).show();
  catch(Exception ex) {
    Toast.makeText(getApplicationContext(), "error->"+ ex.toString(), Toast.LENGTH_SHORT).show();
    ex.printStackTrace();
  }
}

1 个答案:

答案 0 :(得分:1)

<uses-permission android:name="android.permission.INTERNET" />