我尝试从android中的库ksoap2调用请求,但在android studio中收到错误:
I/System: core_booster, getBoosterConfig = false
W/System.err: SoapFault - faultcode: 'soap:Client' faultstring: 'Message part {http://rogal.ws.pl/map/thumbnail}GetThumbnail was not recognized. (Does it exist in service WSDL?)' faultactor: 'null' detail: null
W/System.err: at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:136)
W/System.err: at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
W/System.err: at org.ksoap2.transport.Transport.parseResponse(Transport.java:129)
W/System.err: at org.ksoap2.transport.HttpTransportSE.parseResponse(HttpTransportSE.java:304)
W/System.err: at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:276)
W/System.err: at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
W/System.err: at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
W/System.err: at rogal.sieciowyws.MainActivity.requestSoap(MainActivity.java:67)
W/System.err: at rogal.sieciowyws.MainActivity.testConnect(MainActivity.java:46)
W/System.err: at rogal.sieciowyws.MainActivity.access$100(MainActivity.java:19)
W/System.err: at rogal.sieciowyws.MainActivity$LoginTask.doInBackground(MainActivity.java:94)
W/System.err: at rogal.sieciowyws.MainActivity$LoginTask.doInBackground(MainActivity.java:83)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:307)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err: at java.lang.Thread.run(Thread.java:833)
我的android代码如下所示:
public class MainActivity extends AppCompatActivity {
public static final String SOAP_URL = "http://92e7a7ca.ngrok.io/api/map?wsdl";
public static final String NAMESPACE = "http://rogal.ws.pl/map/MapService/";
public static final String METHOD_NAME = "GetThumbnail";
TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView) findViewById(R.id.textView);
Button signin = (Button) findViewById(R.id.button);
signin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new RequestTask().execute();
}
});
}
private void req() {
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("Name");
propertyInfo.setValue("hello");
requestSoap(propertyInfo);
}
public void requestSoap(PropertyInfo... propertyInfos) {
String mResponse = "";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
for (PropertyInfo propertyInfo : propertyInfos) {
request.addProperty(propertyInfo);
}
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(SOAP_URL);
ht.debug = true;
try {
ht.call("", envelope);
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
try {
mResponse = envelope.getResponse().toString();
text.setText(mResponse);
} catch (Exception e) {
e.printStackTrace();
}
}
private class RequestTask extends AsyncTask<Void, Void, Void> {
protected void onPreExecute() {
System.out.println();
}
protected Void doInBackground(final Void... unused) {
System.out.println();
req();
System.out.println();
return null;
}
protected void onPostExecute(Void result)
{
System.out.println();
}
}
}
我在清单文件中添加了权限:
java中的Web服务:here
wsdl:here
架构xsd:here
我检查了Web服务工具SoapUI的操作并正常工作。
我没有注意到可能导致此异常的错误。
我将非常感谢你的帮助