所以我试图调用ksoap2 webservices并从中获取一些数据,但我一直收到错误而没有输出。在webservices上有一个名为HelloWorld的部分,它只用于测试并且它可以工作,我得到了正确的输出,但是当我试图从这个部分访问数据并且它不起作用时不断出错。
这是代码:
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.MediaController;
import android.widget.VideoView;
import org.ksoap2.HeaderProperty;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import java.util.ArrayList;
import java.util.List;
public class HomeActivity{
private String SOAP_ACTION = "http://microlise.com/TMC/FindConsignmentSummaries";
private String NAME_SPACE = "http://microlise.com/TMC";
private String METHOD_NAME = "FindConsignmentSummaries";
private String url = "https://ws2.microlise.com/canon_live_webservice/TMCWebService.asmx?WSDL";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_page);
MyTask myTask = new MyTask();
myTask.execute();
}
@Override
public void onClick(View v){
}
public class MyTask extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params) {
SoapObject request = new SoapObject(NAME_SPACE, METHOD_NAME);
//request.addProperty("HelloWorld","");
SoapObject filter = new SoapObject( NAME_SPACE,"consignmentFilter");
filter.addProperty("ConsignmentReference","");
filter.addProperty("OrderReference","");
filter.addProperty("EarliestDeliveryDate","");
filter.addProperty("LatestDeliveryDate","");
filter.addProperty("SiteID","");
filter.addProperty("SiteName","");
request.addSoapObject(filter);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransportSE = new HttpTransportSE(url);
httpTransportSE.debug = true;
String requestDump = httpTransportSE.requestDump;
String responseDump = httpTransportSE.responseDump;
try {
List<HeaderProperty> headersProperty = new ArrayList<>();
headersProperty.add(new HeaderProperty("Authorization", "Basic " + android.util.Base64.encodeToString("username:pass".getBytes(), Base64.NO_WRAP))); //org.kobjects.base64.Base64.encode("Technet:CEVA".getBytes())));
httpTransportSE.call(SOAP_ACTION, envelope, headersProperty);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
Log.d("RESULT_IS", " " + response.toString());
Log.d("DEBUG_RESULT", " " + requestDump + " /" + responseDump);
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute () {
}
}
}
这是xml:
POST /canon_live_webservice/TMCWebService.asmx HTTP/1.1
Host: ws2.microlise.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<FindConsignmentSummaries xmlns="http://microlise.com/TMC">
<consignmentFilter>
<ConsignmentReference
xmlns="http://microlise.com/webservices/TMC/">string</ConsignmentReference>
<OrderReference
xmlns="http://microlise.com/webservices/TMC/">string</OrderReference>
<EarliestDeliveryDate
xmlns="http://microlise.com/webservices/TMC/">dateTime</EarliestDeliveryDate>
<LatestDeliveryDate xmlns="http://microlise.com/webservices/TMC/">dateTime</LatestDeliveryDate>
<SiteID xmlns="http://microlise.com/webservices/TMC/">string</SiteID>
<SiteName xmlns="http://microlise.com/webservices/TMC/">string</SiteName>
<SiteAddress xmlns="http://microlise.com/webservices/TMC/">string</SiteAddress>
<SitePostCode xmlns="http://microlise.com/webservices/TMC/">string</SitePostCode>
</consignmentFilter>
</FindConsignmentSummaries>
</soap12:Body>
</soap12:Envelope>
这就是我得到的错误:
Code: soap:Sender, Reason: Server was unable to read request. ---
at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:138)
at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
at org.ksoap2.transport.Transport.parseResponse(Transport.java:129)
at org.ksoap2.transport.HttpTransportSE.parseResponse(HttpTransportSE.java:304)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:276)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
任何想法可能出错?谢谢你们