SOAP Web サービスを呼び出すアプリケーションを開発しています。Web サービスは、ローカル マシンのスタンドアロン OC4J サーバーにデプロイされます。
ブラウザから Web サービスを呼び出すと、正常に動作します。しかし、アプリケーションから呼び出すと、エラーが発生します。
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
Googleで検索したところ、アプリにINTERNET権限を挿入する必要があることがわかりました。しかし、それはすでに与えられています。
私は今どうすればいい。これについて私を案内してください。私はグーグルで検索しましたが、良い解決策はありませんでした。