我有這個位置的web服務:Android - 當我在設備上運行它時無法訪問webservice,但使用AVD它正在工作。爲什麼?
<wsdlsoap:address location="http://app.example.com:8080/WSTest/services/Hello"/>
而且我想在我的Android應用程序訪問此WebService。我這樣做:
private class ConnectTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
private final String NAMESPACE = "http://ws.audiomobil.com";
private final String URL = "http://app.example.com:8080/WSTest/services/Hello?wsdl";
private final String SOAP_ACTION = "http://ws.audiomobil.com/hello";
private final String METHOD_NAME = "hello";
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
String firstName = "Android";
String lastName = "Program";
/*
// Pass value for fname variable of the web service
PropertyInfo fnameProp = new PropertyInfo();
fnameProp.setName("fname"); // Define the variable name in the web service method
fnameProp.setValue(firstName); // Define value for fname variable
fnameProp.setType(String.class); // Define the type of thevariable
request.addProperty(fnameProp); // Pass properties to thevariable
// Pass value for lname variable of the web service
PropertyInfo lnameProp = new PropertyInfo();
lnameProp.setName("lname");
lnameProp.setValue(lastName);
lnameProp.setType(String.class);
request.addProperty(lnameProp);
*/
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,60000);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
String s = response.toString();
System.out.println("WS: " + s);
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
return null;
}
}
++++++編輯 我的WebService類是這樣的:
public class Hello {
public String hello(String fname, String lname){
return "Hello";
}
}
+++++++
當我運行這對我的AVD模擬器 Android 4.0.3然後它的工作正常。它可以訪問web服務,並獲得響應。
但是,當我在我的設備上運行它版本4.0.3,那麼它不起作用。它在這一點停止:androidHttpTransport.call(SOAP_ACTION, envelope);
它拋出一個XMLPullParserException。繼承人logcat:
01-23 11:24:36.959: I/System.out(8172): org.xmlpull.v1.XmlPullParserException:
unterminated entity ref (position:TEXT @1:86 in [email protected])
我真的不知道如何發生這種情況。任何人都可以幫我嗎?
是移動互聯網上的設備,當你運行該應用程序? – SudoRahul
yes intnernet已打開。 –