确保Web服务的URL是可达通过使用下面的代码后通过观察变量urlc.getResponseCode()
为响应代码,同时更改IP从本地主机,固定,外部和最后到10.0.2.2
public static boolean isNetworkAvailable() {
//http://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-timeouts/4009133#comment24565402_4009133
/* ConnectivityManager cm =
(ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {//netInfo.isConnectedOrConnecting()
return true;
}
return false;*/
//http://stackoverflow.com/questions/5474089/how-to-check-currently-internet-connection-is-available-or-not-in-android?rq=1
boolean connected = false;
ConnectivityManager connectivityManager = (ConnectivityManager)_context.getSystemService(Context.CONNECTIVITY_SERVICE);
if(connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED ||
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
//we are connected to a network
connected=true;
return connected;
}
else
{
connected=false;
return false;
}
}
public static boolean hasActiveInternetConnection() {
if (isNetworkAvailable()) {
try {
//String url = "http://www.google.com",
String url = "http://10.0.2.2:8089/UNIV_AXIS_DYN_WEB/services/ServiceMethods?wsdl",
proxy = "proxy.rss.jo",
port= "8080";
URL server = new URL(url);
Properties systemProperties = System.getProperties();
/*systemProperties.setProperty("http.prosyHost",proxy);
systemProperties.setProperty("http.prosyHost",port);*/
HttpURLConnection urlc = (HttpURLConnection) (server.openConnection());
urlc.setRequestProperty("User-Agent", "Test");
urlc.setRequestProperty("Connection", "close");
urlc.setConnectTimeout(500);
urlc.connect();
System.out.println(urlc.getResponseCode());
return (urlc.getResponseCode() == 200);
} catch (IOException e) {
Log.e(LOG_TAG, "Error checking internet connection", e);
return false;
}
} else {
Log.d(LOG_TAG, "No network available!");
return false;
}
}
对我来说,我得到了这个提示 “而不是缺少的字符小号在下面的”
[ERROR] Exception occurred while trying to invoke service method login org.apache.axis2.AxisFault: namespace mismatch require http://services.univ.rss found http://service.univ.rss
日志其余的Tomcat等
at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:190)
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
是的,在追踪LogCat之后,我没有检查tomcat如果该服务被SoapUi成功测试服务器日志前夕,你应该监视每一个变化测试所有的日志,我甚至在第一次忘了启动数据库服务,所以要小心:)
SOAP调用
public SoapObject SoapCall(Vector<PropertyInfo> propertyInfo)
{
Integer parametersSize = propertyInfo.size();
//Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
for(int i=0;i<parametersSize;i++)
{
request.addProperty(propertyInfo.get(i));
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//envelope.dotNet = false; if service of type asmx .NET
envelope.setOutputSoapObject(request);
Log.d("App Log c ","c");
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
System.out.println(androidHttpTransport.getPort());
// Make the soap call.
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
//Log.i("App Log 1 ", response.toString());
} catch (Exception e) {
e.printStackTrace();
}
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
Log.i("App Log 2 ", result.toString());
Log.i("App Log 2 ", result.getProperty(0).toString());
return result;
}
Vector<PropertyInfo> vectorProperyInfo = new Vector<PropertyInfo>();
PropertyInfo userProp = new PropertyInfo();
userProp.setName("userName");
userProp.setValue(username);
userProp.setType(String.class);
vectorProperyInfo.addElement(userProp);
PropertyInfo passProp = new PropertyInfo();
passProp.setName("pass");
passProp.setValue(password);
passProp.setType(String.class);
vectorProperyInfo.addElement(passProp);
SoapObject result = soapUtil.SoapCall(vectorProperyInfo);
if (result != null && result.getProperty(0).toString().equals("1")) {
return "LOGIN_SUCCESS";// for a student
}
PS我的DB是Oracle和Web服务是肥皂和u sed axis2-1.2 bin并在Android 4.0上测试上述错误响应代码是500 Internal Error
是您的.NET webservice返回一个原始类型?如果没有,那么你应该尝试使用SoapObject来代替SoapPrimitive类型。 – Varun 2010-12-09 06:18:14
它返回一个字符串,所以是的... SoapObject应该在这里,但那不是我正在面临的问题。它卡在transportSE.call(SOAP_ACTION,soapSerializationEnvelope); 那么,我如何看到实际/原始soapenvelope ...为验证目的,因为在解析异常发生的调用方法 – Yogurt 2010-12-09 06:22:05