gpt4 book ai didi

java - Android Studio使用kso​​ap库调用Argos WebService错误

转载 作者:行者123 更新时间:2023-12-01 11:18:10 26 4
gpt4 key购买 nike

我是新手。我正在尝试从 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使用kso​​ap库调用Argos WebService错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31543983/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com