我尝试通过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();
}
}
答案 0 :(得分:1)
<uses-permission android:name="android.permission.INTERNET" />