作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是新手。我正在尝试从 Android Studio 调用 Argos Web 服务。
网址:http://ws-argos.cls.fr/argosDws/services/DixService?wsdl
但是当我想调用该函数时,我会抛出 xml
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:typ="http://service.dataxmldistribution.argos.cls.fr/types">
<soap:Body>
<typ:xmlRequest>
<typ:username>*****</typ:username>
<typ:password>*****</typ:password>
<typ:platformId>149343</typ:platformId>
<typ:nbDaysFromNow>10</typ:nbDaysFromNow>
</typ:xmlRequest>
</soap:Body>
</soap:Envelope>
至http://ws-argos.cls.fr/argosDws/services/DixService?getXml获取 Web 服务响应。我不知道为什么,但如果我将 Xml 扔到 http://ws-argos.cls.fr/argosDws/services/DixService?wsdl,我将获得 Web 服务架构而不是响应。
在我的 Android Studio 中,我的代码将是
private static final String SOAP_ACTION = "getXml";
private static final String NAMESPACE = "http://service.dataxmldistribution.argos.cls.fr/types";
private static final String MAIN_REQUEST_URL = "http://ws-argos.cls.fr/argosDws/services/DixService?wsdl";
public String getXml(String username, String password, String PlatformId, String nbDaysFromNow) {
String data = null;
String methodname = "xmlRequest";
SoapObject request = new SoapObject(NAMESPACE, methodname);
request.addProperty("username", username);
request.addProperty("password", password);
request.addProperty("platformId", PlatformId);
request.addProperty("nbDaysFromNow", nbDaysFromNow);
SoapSerializationEnvelope envelope = getSoapSerializationEnvelope(request);
HttpTransportSE ht = getHttpTransportSE();
try {
ht.call(SOAP_ACTION, envelope);
SoapPrimitive resultsString = (SoapPrimitive)envelope.getResponse();
data = resultsString.toString();
} catch (SocketTimeoutException t) {
t.printStackTrace();
} catch (IOException i) {
i.printStackTrace();
} catch (Exception q) {
q.printStackTrace();
}
return data;
}
private final SoapSerializationEnvelope getSoapSerializationEnvelope(SoapObject request) {
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setAddAdornments(false);
envelope.setOutputSoapObject(request);
return envelope;
}
private final HttpTransportSE getHttpTransportSE() {
HttpTransportSE ht = new HttpTransportSE(Proxy.NO_PROXY,MAIN_REQUEST_URL,60000);
ht.debug = true;
return ht;
}
但我总是在 ht.call(SOAP_ACTION, 信封); 上遇到错误
07-22 14:02:43.562 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ android.os.NetworkOnMainThreadException
07-22 14:02:43.562 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
07-22 14:02:43.562 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
07-22 14:02:43.562 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
07-22 14:02:43.562 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at java.net.InetAddress.getAllByName(InetAddress.java:215)
07-22 14:02:43.563 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at com.android.okhttp.HostResolver$1.getAllByName(HostResolver.java:29)
07-22 14:02:43.563 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:232)
07-22 14:02:43.563 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:124)
07-22 14:02:43.563 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:272)
07-22 14:02:43.563 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
07-22 14:02:43.563 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
07-22 14:02:43.563 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
07-22 14:02:43.563 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:217)
07-22 14:02:43.563 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at org.ksoap2.transport.ServiceConnectionSE.openOutputStream(ServiceConnectionSE.java:126)
07-22 14:02:43.563 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:185)
07-22 14:02:43.563 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
07-22 14:02:43.564 2846-2846/com.ecocean.ecoceansharkrace W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
命名空间、主 URL、soap_action 和方法名称是否正确?对不起我的英语不好。我不是英语母语。
最佳答案
通过添加完成
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
另一种选择是使用 AsyncTask
关于java - Android Studio使用ksoap库调用Argos WebService错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31543983/
我是一名优秀的程序员,十分优秀!