我正在开发一个调用 SOAP Web 服务的应用程序。Web 服务部署在本地机器上的独立 OC4J 服务器上。
当我从浏览器调用网络服务时,它工作正常。但是当我从我的应用程序中调用它时,它给了我错误。
调用web服务的代码如下:
package com.abc.myapp.webservice;
import java.io.ByteArrayInputStream;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import com.ocs.manageyourgroup.parsing.DataHandler;
public class WebServiceConnection {
final String NAMESPACE = "http://myapp.abc.com/";
final String URL = "http://localmachine:8888/MyApp-MyApplication-context-root/MyAppSoapHttpPort";
String xml = null;
public void soapRequest(){
String SOAP_ACTION = "http://myapp.abc.com/getApplicationName";
String METHOD_NAME = "getApplicationName";
//Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.debug = true;
//this is the actual part that will call the
androidHttpTransport.call(SOAP_ACTION, envelope);
// Get the SoapResult from the envelope body.
xml = androidHttpTransport.responseDump;
Log.d("Data", xml);
} catch (Exception e) {
e.printStackTrace();
}
}
}
我在运行我的应用程序时,在 logcat 中出现错误:
06-01 18:26:42.094: D/dalvikvm(19946): GC_EXTERNAL_ALLOC freed 59K, 52% free 2584K/5379K, external 716K/1038K, paused 50ms
06-01 18:26:44.413: D/szipinf(19946): Initializing inflate state
06-01 18:26:45.153: W/System.err(19946): java.net.UnknownHostException: localmachine
06-01 18:26:45.208: W/System.err(19946): at java.net.InetAddress.lookupHostByName(InetAddress.java:506)
06-01 18:26:45.213: W/System.err(19946): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
06-01 18:26:45.213: W/System.err(19946): at java.net.InetAddress.getAllByName(InetAddress.java:256)
06-01 18:26:45.225: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69)
06-01 18:26:45.225: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
06-01 18:26:45.233: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
06-01 18:26:45.233: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
06-01 18:26:45.233: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
06-01 18:26:45.247: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
06-01 18:26:45.253: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
06-01 18:26:45.253: W/System.err(19946): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:46)
06-01 18:26:45.253: W/System.err(19946): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:68)
06-01 18:26:45.253: W/System.err(19946): at com.ocs.manageyourgroup.webservice.WebServiceConnection.soapRequest(WebServiceConnection.java:38)
06-01 18:26:45.253: W/System.err(19946): at com.ocs.manageyourgroup.webservice.WebServiceConnection.getApplicationName(WebServiceConnection.java:23)
06-01 18:26:45.253: W/System.err(19946): at com.ocs.manageyourgroup.controllers.SplashScreenActivityController.getApplicationName(SplashScreenActivityController.java:24)
06-01 18:26:45.263: W/System.err(19946): at com.ocs.manageyourgroup.activities.SplashScreenActivity$AsyncLoadDatabase.onPostExecute(SplashScreenActivity.java:54)
06-01 18:26:45.263: W/System.err(19946): at com.ocs.manageyourgroup.activities.SplashScreenActivity$AsyncLoadDatabase.onPostExecute(SplashScreenActivity.java:1)
06-01 18:26:45.263: W/System.err(19946): at android.os.AsyncTask.finish(AsyncTask.java:417)
06-01 18:26:45.263: W/System.err(19946): at android.os.AsyncTask.access$300(AsyncTask.java:127)
06-01 18:26:45.263: W/System.err(19946): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
06-01 18:26:45.263: W/System.err(19946): at android.os.Handler.dispatchMessage(Handler.java:99)
06-01 18:26:45.263: W/System.err(19946): at android.os.Looper.loop(Looper.java:123)
06-01 18:26:45.273: W/System.err(19946): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-01 18:26:45.273: W/System.err(19946): at java.lang.reflect.Method.invokeNative(Native Method)
06-01 18:26:45.273: W/System.err(19946): at java.lang.reflect.Method.invoke(Method.java:507)
06-01 18:26:45.273: W/System.err(19946): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-01 18:26:45.283: W/System.err(19946): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-01 18:26:45.283: W/System.err(19946): at dalvik.system.NativeStart.main(Native Method)
06-01 18:26:45.333: W/System.err(19946): java.net.UnknownHostException: localmachine
06-01 18:26:45.333: W/System.err(19946): at java.net.InetAddress.lookupHostByName(InetAddress.java:497)
06-01 18:26:45.333: W/System.err(19946): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
06-01 18:26:45.333: W/System.err(19946): at java.net.InetAddress.getAllByName(InetAddress.java:256)
06-01 18:26:45.333: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69)
06-01 18:26:45.333: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
06-01 18:26:45.343: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
06-01 18:26:45.343: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
06-01 18:26:45.343: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
06-01 18:26:45.343: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
06-01 18:26:45.343: W/System.err(19946): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
06-01 18:26:45.343: W/System.err(19946): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:46)
06-01 18:26:45.353: W/System.err(19946): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:68)
06-01 18:26:45.353: W/System.err(19946): at com.ocs.manageyourgroup.webservice.WebServiceConnection.soapRequest(WebServiceConnection.java:38)
06-01 18:26:45.353: W/System.err(19946): at com.ocs.manageyourgroup.webservice.WebServiceConnection.getApplicationName(WebServiceConnection.java:23)
06-01 18:26:45.353: W/System.err(19946): at com.ocs.manageyourgroup.controllers.SplashScreenActivityController.getApplicationName(SplashScreenActivityController.java:24)
06-01 18:26:45.353: W/System.err(19946): at com.ocs.manageyourgroup.activities.SplashScreenActivity$AsyncLoadDatabase.onPostExecute(SplashScreenActivity.java:55)
06-01 18:26:45.353: W/System.err(19946): at com.ocs.manageyourgroup.activities.SplashScreenActivity$AsyncLoadDatabase.onPostExecute(SplashScreenActivity.java:1)
06-01 18:26:45.353: W/System.err(19946): at android.os.AsyncTask.finish(AsyncTask.java:417)
06-01 18:26:45.353: W/System.err(19946): at android.os.AsyncTask.access$300(AsyncTask.java:127)
06-01 18:26:45.353: W/System.err(19946): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
06-01 18:26:45.363: W/System.err(19946): at android.os.Handler.dispatchMessage(Handler.java:99)
06-01 18:26:45.363: W/System.err(19946): at android.os.Looper.loop(Looper.java:123)
06-01 18:26:45.363: W/System.err(19946): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-01 18:26:45.363: W/System.err(19946): at java.lang.reflect.Method.invokeNative(Native Method)
06-01 18:26:45.363: W/System.err(19946): at java.lang.reflect.Method.invoke(Method.java:507)
06-01 18:26:45.363: W/System.err(19946): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-01 18:26:45.363: W/System.err(19946): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-01 18:26:45.363: W/System.err(19946): at dalvik.system.NativeStart.main(Native Method)
06-01 18:26:47.613: D/dalvikvm(19946): GC_EXTERNAL_ALLOC freed 130K, 52% free 2633K/5379K, external 1359K/1828K, paused 49ms
06-01 18:26:47.944: D/dalvikvm(19946): GC_EXTERNAL_ALLOC freed 10K, 52% free 2630K/5379K, external 2181K/2471K, paused 60ms
我在谷歌上搜索,发现我需要在应用程序中插入 INTERNET 权限。但它已经给出了。
我现在该怎么办。请指导我。我在谷歌上搜索但没有得到任何好的解决方案。